gikay01
February 14, 2008, 1:43pm
1
I am trying to substitute something with sed and what I want is to substitute a whole
word and not part of a word. ie
sed 's/class/room/g' filename
will substitute both class and classes into room and roomes which is not what i want
Grep for instance can use the -w option or <>
grep -w class
and in that case it will not get classes.
Don't know about sed but wanted to implement something like that
joeyg
February 14, 2008, 2:30pm
2
sed 's/class /room /g' filename
gikay01
February 15, 2008, 6:53pm
3
Thank for your suggestion
That won't handle lines that end in 'class' or words that end in class (say 'p-class' for example).
I'd suggest looking for words that are proceeded by either a space or start of line, AND end in a space or end of line.
use:
sed 's/class\>/room/g' filename
the above will only replace lines that end with class and will ignore classes.
Ikon
July 16, 2008, 4:31pm
6
But that will replace class and whateverclass.
sed 's/^class$/room/g' filename
EDIT: This is WRONG, see post below!!
Then use this:
sed 's/\<class\>/room/g' filename
Should only replace words that start and end with class.