简体   繁体   English

我想使用AND grep操作,但是我不知道如何

[英]I want to use AND grep operation, but i don't know how

There are one program named pro1 and one data file named file1 in the folder. 该文件夹中有一个名为pro1的程序和一个名为file1的数据文件。

In data file, 在数据文件中

Alex|New york karlos|011-1234-5678
Karl|Chicago koroq|012-3456-7890
Richard|New york ntown|023-4567-8990

And I'd like to use grep AND. 而且我想使用grep AND。

I write down this code, but it didn't work 我记下了这段代码,但是没有用

for arg in $@; do
if[ count -eq 1]
then
  egrep -i $arg file1 | $temp
else
  egrep -i $arg $temp | $temp
fi
done

echo $temp 回声$ temp

When I enter "./pro1 Alex New york" I want to print Alex|New york karlos|011-1234-5678 当我输入“ ./pro1 Alex New york”时,我要打印Alex |纽约karlos | 011-1234-5678

How can i do it?? 我该怎么做??

File 'mgrep': 文件“ 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

Run it like this: 像这样运行它:

cat file1 | mgrep one two three

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

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