I would like to search the file with GREP for the "User-Agent: UA" and then extract the closest line above that has "Via:" My problem is that sometimes there are multiple lines with "Via:", but I need only last one.
For example file to parse:
Via: 1.1.1.1
not relevant line
...
not relevant line N
User-Agent: UA
...
Via: 2.2.2.2
Via: 3.3.3.3
not relevant line
...
not relevant line N
User-Agent: UA
...
Via: 4.4.4.4
Via: 5.5.5.5
Via: 6.6.6.6
not relevant line
...
not relevant line N
User-Agent: UA
Result I want is the lines that contain "Via:" closest to "User-Agent: UA"
Via: 1.1.1.1
Via: 3.3.3.3
Via: 6.6.6.6
Any help will be appreciated.