简体   繁体   English

zgrep关于多个输入变量的问题

[英]zgrep on multiple input variables issue

I have an issue using zgrep . 我在使用zgrep遇到问题。 I want to look for a XML file based on an ID and a certain Date given by the user. 我想根据用户指定的ID和特定Date查找XML文件。 Each XML file contains an ID and a date in it. 每个XML文件都包含一个ID和一个日期。 The program should acknowledge that these files may have the same ID but a different Date. 程序应确认这些文件可能具有相同的ID,但日期不同。 I tried to use zgrep but I don't know how to look for two different variables and my code doesn't work. 我尝试使用zgrep,但是我不知道如何查找两个不同的变量,并且我的代码无法正常工作。 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! 多谢您的协助!

You cannot grep both ID and Date with a single grep command if they are not on the same line. 如果ID和日期不在同一行,则不能使用单个grep命令对ID和日期进行grep。 Try this: 尝试这个:

find . -print0 | xargs -0 zgrep -lZ -e "$InputCode" | xargs -0 zgrep -l -e "$Date"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM