leoberbert has asked for the wisdom of the Perl Monks concerning the following question:
I have the file below in the following format
Success|Filter passed|[invalid field]|[invalid field]|Id-350a875b08796 +5e58cbe1f4a Accept: text/plain, text/plain, application/json, application/*+json, +*/*, */* Host: api2.tim.com.br User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.3 +6 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Via: 1.1 X-Forwarded-For: 144.22.98.123 X-Forwarded-Host: X-Forwarded-Server: Success|Success in calling policy shortcut|[invalid field]|[invalid fi +eld]|[invalid field]|Id-350a875b087965e58cbe1f4a|Call 'Set Request Me +ssage'|GET Accept: text/plain, text/plain, application/json, application/*+json, +*/*, */* Host: api2.tim.com.br User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.3 +6 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Via: 1.1 api2.tim.com.br X-Forwarded-For: 144.22.98.123 X-Forwarded-Host: X-Forwarded-Server: Content-Type: text/xml; charset="UTF-8"
I need to perform a search for the line that begins with the string "^ Success" and display all the items until there is a "^ Sucess" string again.
Here is an example of what I need to display:
Success|Filter passed|[invalid field]|[invalid field]|Id-350a875b08796 +5e58cbe1f4a Accept: text/plain, text/plain, application/json, application/*+json, +*/*, */* Host: api2.tim.com.br User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.3 +6 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Via: 1.1 X-Forwarded-For: 144.22.98.123 X-Forwarded-Host: X-Forwarded-Server:
What happens is that the amount of lines below after the match is very dynamic.
What happens is that the amount of lines below the match is very dynamic and in the same file there may be several lines of the same match and I would need to display them also when the file is run.
I do not know how to get the next line until the next occurrence. I can only catch the line of occurrence.
Could you guys help me?while ($line = <STDIN>) { chomp $line; if($line =~ /^Success.*Id-9952895b108957daeb296ba4/i) { print "$line\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Search after match in dynamic lines
by choroba (Cardinal) on Aug 31, 2018 at 16:24 UTC | |
by haukex (Archbishop) on Sep 01, 2018 at 06:58 UTC | |
|
Re: Search after match in dynamic lines
by haukex (Archbishop) on Aug 31, 2018 at 16:19 UTC | |
|
Re: Search after match in dynamic lines
by AnomalousMonk (Archbishop) on Aug 31, 2018 at 16:20 UTC | |
|
Re: Search after match in dynamic lines
by Marshall (Canon) on Aug 31, 2018 at 21:26 UTC |