New answers tagged awk
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&...
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
Top 50 recent answers are included
Related Tags
awk × 615sed × 236
bash × 206
linux × 197
grep × 100
shell × 57
unix × 55
command-line × 54
perl × 43
regex × 41
shell-script × 37
csv × 24
text-editing × 24
bash-scripting × 22
script × 21
find × 17
ubuntu × 11
pipe × 11
windows × 10
macos × 10
python × 8
sorting × 8
uniq × 8
string × 7
cut × 7