7

I want to remove word 'foggy' from the string. It fails. Why?

echo 'foggy light' | sed 's/\<foggy\>//g'
muru
  • 197,895
  • 55
  • 485
  • 740
Josef Klimuk
  • 1,596
  • What version of Ubuntu? What's the output of sed --version? – muru Feb 18 '18 at 11:39
  • @userunknown of course: GNU sed, installed by default on all versions of Ubuntu, has \< and \> for matching start-of-word and end-of-word. I suspect this is yet another Android question. OP has been know to post a number of questions about some Android app that provides Unix commands, while pretending it is Ubuntu OP is using. – muru Feb 18 '18 at 12:24
  • For removing the word foggy in above scenario, you don't need start-of-word/end-of-word-markers. – user unknown Feb 18 '18 at 12:33
  • sed version 4.0 – Josef Klimuk Feb 18 '18 at 13:13
  • Which it is not on any current version of Ubuntu: https://packages.ubuntu.com/search?keywords=sed, so yet again an off-topic question. – muru Feb 18 '18 at 13:18

1 Answers1

14

In the above string, you don't need start-of-word/end-of-word markers and you may use:

echo 'foggy light' | sed 's/foggy//g'

For the additional question in the comment:

Indeeed, my sed version

sed --version
sed (GNU sed) 4.2.2

supports the Syntax with \<...\>

echo 'foggy foggylight' | sed 's/\<foggy\>//g'
foggylight

If it doesn't work for you, report your sed version and read its manpage. For my sed, this syntax works too:

echo 'foggy foggylight' | sed 's/\bfoggy\b//g'
foggylight

\b can be memorized as boundary.

muru
  • 197,895
  • 55
  • 485
  • 740
user unknown
  • 6,507