i have a text file which looks like this:
random useless text <!-- this is token 1 --> para1 para2 para3 <!-- this is token 2 --> random useless text again
I want to extract the text in between the tokens (excluding the tokens of course). I tried using ## and %% to extract the data in between but it didn't work. I think it is not meant for manipulating such large text files. Any suggestions how i can do it ? maybe awk or sed ?
The G command appends a newline and the hold space to the end of the pattern space. Since, by default, the hold space is empty, this has the effect of just adding an extra newline at the end of each line. The prefix $! tells sed to do this on all lines except the last one.
To print a document on the default printer, just use the lp command followed by the name of the file you want to print.
Use comm -12 file1 file2 to get common lines in both files. You may also needs your file to be sorted to comm to work as expected. Or using grep command you need to add -x option to match the whole line as a matching pattern. The F option is telling grep that match pattern as a string not a regex match.
No need for head
and tail
or grep
or to read the file multiple times:
sed -n '/<!-- this is token 1 -->/{:a;n;/<!-- this is token 2 -->/b;p;ba}' inputfile
Explanation:
-n
- don't do an implicit print/<!-- this is token 1 -->/{
- if the starting marker is found, then :a
- label "a" n
- read the next line/<!-- this is token 2 -->/q
- if it's the ending marker, quitp
- otherwise, print the lineba
- branch to label "a"}
end ifIf 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