Monday, June 16, 2014

How to change the word in the file in aix?

How to change the word in the file in aix?


Using the below commands we can change the particular word in the file. 

Note: we can replace the word and save into the other file. NOT on the target file itself. if we try to replace the word on the same file itself, the file will be nullified automatically.


      sed "s/ <target_word> / <replacing_word> /g" newfile > newfile-backup


In the above commands, we can replace the word from test_old to test_new on the newfile.

Ex: 

cat newfile

test_1
test_2
test_3
test_old
test_5
test_6
test_old

sed "s/test_old/test_new/g" newfile > newfile_backup

cat newfile

test_1
test_2
test_3
test_new
test_5
test_6
test_new


On the above newfile, test_old has been replaced by test_new. (So whereever the word "test_old" is there in the file, it has been replaced by the new word "test_new")