![](/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.