LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Help With RegExp.. Somedata +....+ Somedata (https://www.linuxquestions.org/questions/linux-software-2/help-with-regexp-somedata-somedata-575892/)

ALInux 08-09-2007 09:10 AM

Help With RegExp.. Somedata +....+ Somedata
 
Hi All I am trying to parse a logfile to get the data from StringA to StringB with all the data in between..the data between StringA and StringB spreads over multiple lines example..

StringA .data data
data
data
data ..StringB

I am trying :

cat /usr/local/mylog.log | grep -E 'StringA.*StringB'

Should I use SED..? Can any provide me with an example ?

Thx for any help

druuna 08-09-2007 11:04 AM

Hi,

Something like this should work:

sed -n '/StringA/,/StringB/p' infile

The above will only print what's between StringA and StringB (both are included in output).
You can use regular expressions for line ranges in sed. Instead of the 'standard' 1,4 (print lines 1 to 4) you can do /xxx/,/yyy/ where xxx and yyy are reg. expr. You can also combine them (1,/zzz/).

Hope this helps.


All times are GMT -5. The time now is 05:52 PM.