0

All I need is the Zip file name. In the first step I searched for the author:

egrep -ni -B1 --color "$autor: test_autor" file_search_v1.log > result1.log

whatever worked, the result was:

zip: /var/www/dir_de/html/dir1/dir2/7890971.zip
author: test_autor
zip: /var/www/dir_de/html/dir1/dir2/10567581.zip
author: test_autor

But, as mentioned above, the Ziip file name. In the second step I tried to filter the result of the first search again:

egrep -ni -B1 --color "$autor: test_autor" file_search_v1.log | xargs grep -i -o "\/[[:digit:]]]\.zip"

to search only for the filename, unfortunately this does not work.

My question. How should the second grep filter "look" so that I only get the zip file name?

1
  • Could you please paste a few lines of file_search_v1.log so we know what the original file looks like?
    – markgraf
    Nov 25 '19 at 14:26
0
grep -B1 "$autor: test_autor" file_search_v1.log | grep -o "[^/]*\.zip$"

Change the first grep as needed. The second grep filters out the parts at the end of the line containing non-/ characters followed by the .zip suffix.

If you know that your zip files only contains digits, you could exchange [^/] with [[:digit:]].

0

With single awk expression:

$ author="test_autor"
$ awk -v pat="author: $author" '$0 ~ pat{ sub(/^.*\//, "", zip); print zip }{ zip=$0 }' file
7890971.zip
10567581.zip
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.