-4

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?

MelBurslan
  • 6,966

1 Answers1

1

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
DopeGhoti
  • 76,081