How can I find a string in a file, then find the first instance of a line that contains 'srv' that precedes it.
I have been looking at Tac and sed, but have been unsuccessful at getting it to work right.
Output file to search looks like
srv-test-1 | SUCCESS | rc=0 >> a1 A3 srv-test-2 | SUCCESS | rc=0 >> a1 b1 b2 B3 B4
The code prompts the user for the string they are looking for and stores it to a variable.
I am able to find the users request using
tac file | grep $requested
if the user requests b1, I would like it to return
b1 found on srv-test-2
and likewise if requesting a1 it would return
a1 found on srv-test-1 a1 found on srv-test-2