For example, file
/abc /abc/def /abc/xyz /abcd /fghi
Give input and expected results are:
/abc/dog => /abc /abc/def12 => /abc/def /dog => (NONE)
Is this possible using only shell commands or
awk, etc. stuff?
One way to do this is to somewhat reverse the idea of which is the input and use
These won't output anything for "/dog", although the
This will more closely match your requested output:
You can force the search patterns to start at the beginning of the line like this:
Sounds like a job for Perl, so here's an awk solution. Minimally tested.
A simple shell script should do the job:
You can use it like:
and it will print the longest match of the query