sed: pattern matching with newlines
Hi
How do I get sed to read patterns within newlines ? Code:
sed -i 's|hello.*?world|just-hello|g' *.txt |
You need to build up more than one line in either the pattern space or the hold space. Then have commands that use `\n' for the newline. The $ metacharacter will match the end of the buffer and not an embedded newline.
Use the N command to append to the pattern space, and H to append to the hold space. Code:
cat testfile.txt Code:
sed '/Hello/{ s/Hello World/Just Hello/;t |
Or maybe use a tool better designed for the task - perl, or even awk.
|
All times are GMT -5. The time now is 08:11 PM. |