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"; } }
In reply to Search after match in dynamic lines by leoberbert
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |