1

Is it possible to use sed to replace words, but avoid replacing words that begin with the letters?

For example if I replace man with woman, but women becomes wowoman is it possible to skip woman with sed? Or would you pipe in sed again to remove wo from the beginning of the letters ?

sed -i 's/man/woman/g' /usr/share/dict/words | sed 's^wo//'g /usr/share/dict/words 

which doesn't seem to be working just add another wo on the start.

After reading more on piping grep into sed i tried the following command

sudo sed -i 's/man/woman | grep -v 'woman'/g' words1 

what i am looking to try out is replace all letter that have man with woman

1

Only replace "man" if it's a single word:

sed -i 's/\bman\b/woman/g' /usr/share/dict/words
  • after reading on passing grep into sed i tried this command 'sudo sed -i 's/man/woman | grep -v 'woman'/g' words1' the output of the file is wowoman | grep -v woman – David Sep 22 '16 at 20:32
  • Please watch your command carefully. sed 's/xxx/yyy/g' is replacing "xxx" by "yyy". So your command will replace "man" by "wowoman | grep -v woman" – rudimeier Sep 22 '16 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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