BASH: Output everything between two strings
Hi. im sure this sort of question is probably asked a lot, but I can't seem to find any helpful info.
I am writing a bash script. What I want is something which will search a file and output everything between two strings. e.g. if the file contains something like this: <HTML> <!--Description="this is a random example page"--> <BODY> <!--Heres some content--> blahblahblahdablah </BODY> </HTML> i want to put in something like: from "<!--Description=\"" to "\"-->" and get: this is a random example page I did try using grep, but I havent the faintest idea how to use it, and the man page didnt make it look like it was capable of this. Thanks in advance Simon |
Just a first shot ...
Code:
grep "<!--" temp.html | sed 's/<!--\(.*\)-->/\1/g' Gives Cheers, Tink Code:
grep '<!--' temp.html | sed 's/<!--\(.*\)-->/\1/g' |
Thanks!
I didn't actually want it to output the "Here's some content" bit, I put that in there because I wanted it to destinguish between <!--Description and other comments. Anyways that doesn't matter because I managed to modify your example to do that. It now looks like this: Code:
grep '<!--Description' temp.html | sed 's/<!--Description="\(.*\)"-->/\1/g' Code:
this is a random example page Simon |
All times are GMT -5. The time now is 02:35 PM. |