0

I have an issue using zgrep. I want to look for a XML file based on an ID and a certain Date 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!

Jafet Soto
  • 41
  • 6
  • https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – chepner May 22 '17 at 17:21

1 Answers1

0

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"
Yang Yang
  • 411
  • 3
  • 11