View Single Post
  #5 (permalink)  
Old 07-23-03, 11:08
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
'Chillies' is right - you need to be aware that sed is searching for patterns and has no implicit concept of words.

If you're lucky, your version of sed will support the word boundary chararcters \< and \>, so you could use...

sed 's/\<word\>/new_word/g' yourFile

If you're like me and your sed doesn't support this, you can write a more complex regex...

sed 's/\([^a-Z][^a-Z]*\)word\([^a-Z][^a-Z]*\)/\1new_word\2/g' < yourFile

(the above doesn't take into the 'word' being at the beginning of the line or the end of the line, so you'd have to string a few commands together to get exactly what you want!)

Alternatively, if you have vi (and I'm sure you do), vi should support the word boundary characters.

In a vi session type...

:%s/\<word\>/new_word/g
Reply With Quote