Scanning file backwards

Is there any way to look for a directory path that is listed any number of lines *before* a keyword in an error message?

I have a script that is trying to process different files that are always down a certain portion of a path, and if there is an error, then says there is an error, contact "the vendor". The count of lines between the path/file that's listed and the actual error is always different, so I can't "cut" based on that pattern. Here's basically what it looks like in the log:

\\server\dir\dir\appdir\...\filename
varied number of lines of data
Unknown problem: "Contact the vendor"

Is there any way to look for the keyword "vendor" and scan "backwards" to find the path/file which I can then cut, put into another file, and manipulate further?

Thanks for any help you can provide,

one way with awk (Are you SURE there are \ chars in the filename -- You have to escape them with another \) Assumes filename is in Column 1 on the line:

awk '{ 
        if index("\\", $0) ==1) { file=$0}
        if(index("vendor", $0)>0) { print file}
       }'  logfile

Is there any way to look for the keyword "vendor" and scan "backwards" to find the path/file

$ man grep

check the -B num option

ps: sorry if i didn't understand your problem :stuck_out_tongue: