Find and replace text within a file using commands on linux

Replace a String in Multiple Files in Linux Using Grep and Sed (Find and replace text within a file using commands.)

OS:Linux,Unix

Use grep and sed commands

QUESTION:

How to replace IP adress on dns server(bind) in multiple files in Linux?

SOLUTION:

syntax(format):

grep -rl old_ip /var/named/ | xargs sed -i 's/old_ip/new_ip/g'

Example:

grep -rl ‘80.70.65.12’ ./ | xargs sed -i ‘s/80.70.65.12/55.45.34.2/g’

OR

grep -rl ‘80.70.65.12’  /var/named/ | xargs sed -i ‘s/80.70.65.12/55.45.34.2/g’

I replaced 80.70.65.12 to 55.45.34.2 in multiple zone files.

 

 

Usage vi editor in HP-UX

Important cursor Movement keys

keys Effect
l Move one character right
h Move one character left
j Move one line down
k Move one line up
Move one character right
G Go to last line of the file
nG Go to line number n in the file
$ Go to end of current line
^ Go to start of line
w Go to beginning of next word
b Go to beginning of previous word
e Move to end of word
H Go to first line of screen
M Go to middle line of screen
L Go to last line of screen
( Go to beginning of sentence
) Go to end of sentence
{ Go to beginning of paragraph
} Go to end of paragraph

Text Deletion Commands

Command Effect
x Delete character at current cursor location.
nx Delete n characters starting at current cursor location.
X Delete previous character from the current cursor location.
nX Delete n previous characters from the current cursor location.
dd Delete current line.
db Delete previous word.
dw Delete from current cursor location to the end of word.
dG Delete to the end of file including current line.

HP-UX networking related tools and commands

FILES
  • /etc/hosts – Hosts configuration file (resolve hosts and IPs)
  • /etc/rc.config.d/netconf – IP address, routeing address and hostname stored in this file
SCRIPTS
  • /etc/init.d/net start – Use to start, stop network service     OR
  • /sbin/init.d/net 
HPUX Commands
  1. (a) Display lan interface info
    1.       lanscan
  2. All in one lan configuration utility (lan0 is first Ethernet interface) to configure and view the system IP address:
    1.  ifconfig lan0 – Display IP info such as IP address netmask etc.
    2.  ifconfig lan0 up – Up network interface (allow traffic)
    3.  ifconfig lan0 down – Down network interactive (deny traffc)
    4.  ifconfig lan0 192.168.1.1 netmask 255.255.255.0 up – Setup/change IP adddress
  3. Displaying host name
    1.      hostname
  4. Arp administration (cache)
    1.   arp -a  
  5. Display routing table/info:
    1. netstat -nr
  6.   Define new route:
    1. route add default 192.168.1.254 1
  7. HP’s LAN diagnostic tool
    1. lanadmin
  8. Test a remote host connectivity
    1. ping host.mycorp.com
  9. Setup various lan properties, dns client, NIS client configuration etc using GUI tool:
    1. sam
    2. set_parms
  10.  Check dns connectivity
    1. nslookup http://www.google.com