I have a file with the following text:
text
START
This
has
to
be
printed
STOP
more text
Now i want the text in between START and STOP to be printed. I wrote the following:
cat file | sed '/START/,/STOP/p'
But that does not seem to be doing what i want. Any suggestions?
Regular expressions are used by several different Unix commands, including ed, sed, awk, grep, and to a more limited extent, vi.
Its basic concept is simple: the s command attempts to match the pattern space against the supplied regular expression regexp ; if the match is successful, then that portion of the pattern space which was matched is replaced with replacement . For details about regexp syntax see Regular Expression Addresses.
A regular expression (regex) is a text pattern that can be used for searching and replacing. Regular expressions are similar to Unix wild cards used in globbing, but much more powerful, and can be used to search, replace and validate text.
If you want to print between the start and stop signs, try:
sed -n '/START/,/STOP/ { //!p }' file.txt
Results:
This
has
to
be
printed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With