New answers tagged

0 votes

Substitution in text file **without** regular expressions

Bash can do it! zInput='string .* to .* search' zMatch='.*' zResult='' while :; do [[ "$zInput" =~ (.*)("$zMatch")(.*) ]] || break zResult="replacement${BASH_REMATCH[3]...
Paul's user avatar
  • 103
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
1 vote

Substitution in text file **without** regular expressions

After reading through the many answers here and not finding a straightforward way to do find + replace with string literals (not regular expressions) with sed / git grep: I wrote a small CLI tool to ...
Christian Stewart's user avatar

Top 50 recent answers are included