Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.62 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Replace a word with another in bash
  2. hello sara, my name is sara too.
  3.        
  4. hello mary, my name is mary too.
  5.        
  6. s='hello sara , my name is sara too .'
  7. r=${s//sara/mary}
  8. echo $r
  9.        
  10. sed 's/sara/mary/g' <<< $s
  11. echo $r
  12.        
  13. hello mary , my name is mary too .
  14.        
  15. $ sed s/sara/mary/g <<< 'hello sara , my name is sara too .'
  16. hello mary , my name is mary too .
  17.        
  18. $ cat FILE
  19. hello sara , my name is sara too .
  20. $ sed -i s/sara/mary/g FILE
  21. $ cat FILE
  22. hello mary , my name is mary too .
  23.        
  24. # sed 's/sara/mary/g' FILENAME
  25.        
  26. # perl -p -i -e 's/sara/mary/g;' FILENAME
  27.        
  28. awk '{gsub("sara","mary")}1' <<< "hello sara, my name is sara too."