Marco
Marco

Reputation: 1232

get specific lines in a range pattern from a text file

I am trying different scenarios now, 1 of those is getting the text between the following 2 strings.


Code:

Type of msg:          -in_full [+]
>date
>alr text
>ID_on_exit
AWXX-Ready to commit (96) msg type: (10)
**
Type of msg:          -in_full [+]
>date
>alr text
>ID_on_exit
AWXX-Ready to commit (98) msg type: (10)
**
Type of msg:          -in_full [+]
>date
>alr text
>ID_on_exit
AWXX-Ready to commit (96) msg type: (10)

I need to get all the occurrences having the same start line and end line. Starting with Type of msg ....... and ending with the last line.

The last string must be at the beginning of the line, as well as the 1st string. I said that, because there are cases where that AWXX code appears in the middle of another lines, I am not interested in those.

I tried something like this, but I am not really good with awk

Code:

perl -lne '{if(/"Type of msg:          -in_full \[+\]"/){$#A=-1;$f=1;} if(/^AWXX-Ready to commit (98) msg type: (10)/ && ($f)){print join("\n",@A,$_);next}($f)?push(@A,$_):next;}' test6

I also tried with sed, but my files are big, and I think that there is some kind of limitation because it doesn't work with those files but with little files.

Is there any limitation in the size of the file that we process with SED for example?, now I am using sed and it works only in little files, but not in my 100MB logs.

I am also using the following:

awk '/^Type of msg:          -in_full \[+\]/{s=x}{s=s$0"\n"}/^AWXX-Ready to commit \(98\)/{print s}' test6

For some reason, it shows all the file, instead of what I am looking for. HELP!!

Upvotes: 3

Views: 202

Answers (1)

captcha
captcha

Reputation: 3756

Code for GNU :

sed -n '/^Type of msg:\s\+-in_full.\[+\]/,/^AWXX-Ready to commit (96) msg type:/p' file

Code for GNU :

awk '/^Type of msg:[[:space:]]+-in_full.\[\+\]/,/^AWXX-Ready to commit \(96\) msg type:/' file

Upvotes: 3

Related Questions