Fist I am trying to print a file with the word 'Guess' in it and change the word fall to bar.
This what I have tried:
sed -n -e '/Guess/p' -e 's/Fall/bar/' data.txt
The commands work fine alone however, together only the first part is working.
Fist I am trying to print a file with the word 'Guess' in it and change the word fall to bar.
This what I have tried:
sed -n -e '/Guess/p' -e 's/Fall/bar/' data.txt
The commands work fine alone however, together only the first part is working.
To print line containing 'Guest' and change word 'Fall' in that line,
I would try experimenting with this command>
cat data.txt | sed -n '/Guest/{ s/Fall/bar/p }'
However, this print nothing, if the line with 'Guest' does not contain the word 'Fall'. (Both scenarios - Guest + Fall are required)
If you want to print line containing 'Guest' no matter if substitution finds a word 'Fall', I suggest trying:
cat data.txt | sed -n '/Guest/ { s/Fall/bar/;p }'