Jafet Soto Jafet Soto - 1 year ago 51
Bash Question

zgrep on multiple input variables issue

I have an issue using

. I want to look for a XML file based on an
and a certain
given by the user.
Each XML file contains an ID and a date in it. The program should acknowledge that these files may have the same ID but a different Date. I tried to use zgrep but I don't know how to look for two different variables and my code doesn't work. Here's my code:

echo "Introduce ID: "
read -r InputCode
echo "Set a specific Date [ DD-MM-YYYY ]: "
read -r Date

#Search patterns in every zip folder
find . -print0 | xargs -0 zgrep -l $InputCode && $Date

I would appreciate your help!

Answer Source

You cannot grep both ID and Date with a single grep command if they are not on the same line. Try this:

find . -print0 | xargs -0 zgrep -lZ -e "$InputCode" | xargs -0 zgrep -l -e "$Date"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download