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.)


Use grep and sed commands


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



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


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


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

I replaced to 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

  • /etc/hosts – Hosts configuration file (resolve hosts and IPs)
  • /etc/rc.config.d/netconf – IP address, routeing address and hostname stored in this file
  • /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 netmask 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 1
  7. HP’s LAN diagnostic tool
    1. lanadmin
  8. Test a remote host connectivity
    1. ping
  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

HP-UX Sendmail server is disabled, how to enable it?

  1. try to run
    1.      . /etc/rc.config  to read the variables,
  2. İf output is 0 (disable),set the sendmail to 1(enable)
    1.      # echo $SENDMAIL_SERVER
  3. enable sendmail
    1. vi /etc/rc.config.d/sendmail
    2. export SENDMAIL_SERVER=1
      export SENDMAIL_RECVONLY=0
      export SENDMAIL_SENDONLY=0

Welcome to Blog,

This blog was created to share my experiences to help other people. On this page you can find an information about Linux/Unix (Redhat, HP-UX, OEL, Debian …etc.), backup, storage and troubleshooting topics.