![](/img/trans.png)
[英]How is grep with --include matching this file (when I don't want it to)
[英]I want to use AND grep operation, but i don't know how
该文件夹中有一个名为pro1的程序和一个名为file1的数据文件。
在数据文件中
Alex|New york karlos|011-1234-5678
Karl|Chicago koroq|012-3456-7890
Richard|New york ntown|023-4567-8990
而且我想使用grep AND。
我记下了这段代码,但是没有用
for arg in $@; do
if[ count -eq 1]
then
egrep -i $arg file1 | $temp
else
egrep -i $arg $temp | $temp
fi
done
回声$ temp
当我输入“ ./pro1 Alex New york”时,我要打印Alex |纽约karlos | 011-1234-5678
我该怎么做??
文件“ mgrep”:
#!/bin/bash
TEMP=/tmp/mgrep-$$
touch $TEMP
COUNTER=0
for arg in $@; do
let COUNTER=COUNTER+1
if [ $COUNTER -eq 1 ]; then
grep -i "$arg" > $TEMP
else
TEMP2=/tmp/mgrep-$$-$COUNTER
grep -i "$arg" $TEMP > $TEMP2
rm $TEMP
TEMP=$TEMP2
fi
done
cat $TEMP
rm $TEMP
像这样运行它:
cat file1 | mgrep one two three
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.