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.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s