New answers tagged

3 votes

How do I delete every ocurrence of a word that is followed by another, without altering the whitespace?

With anything which supports perl-compatible regular expressions (PCRE), you can use a positive lookahead: perl -pe 's/foo(?=.*bar)//' < txt (?=) is a "zero-width positive lookahead assertion&...
jcaron's user avatar
  • 1,738
3 votes

How do I delete every ocurrence of a word that is followed by another, without altering the whitespace?

OK, I found out how to do this. The command to do this with sed would be: sed -i -E 's/foo([[:blank:]]*)bar/\1bar/' file
vim_overlord's user avatar

Top 50 recent answers are included