-4

This question already has an answer here:

i have a file in which i have to change a word and then save it by same name.

for ex- for file "name"-

my name is joe (original data)
my name is roy (changed data)

how to do it in best possible way?

marked as duplicate by jasonwryan, Jeff Schaller, garethTheRed, Anthon, don_crissti May 11 '16 at 20:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

To change all occurrences of joe in a file to roy:

sed 's/joe/roy/g' /path/to/the/file > /path/to/new/file

To change all occurrence of joe in a file to roy on lines containing my name:

sed '/my name/s/joe/roy/g' /path/to/the/file > /path/to/new/file
  • but this changes the data in file.. i want to add changes to a new file.. but using '>' doesnot work for me.. plz help.. – Satyam Kapoor May 17 '16 at 15:35
  • I shall edit my answer to reflect that you want the changes to go into a new file. – DopeGhoti May 17 '16 at 18:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.