需求: A文件是一个文件列表,B文件每一行包含了A文件某行,要从B中抽取出包含了A中的行
awk '{print $0}' A.txt | xargs -i grep {} B.txt > outFile
用一个shell脚本实现也是可以的,脚本如下:
#!/bin/sh
if [ $# -ne 3 ];then
echo "parameter error"
echo "usage:`basename $0` regFile targetFile outFile"
exit 1
fi
regFile=$1
targetFile=$2
outFile=$3
if [ ! -f $regFile -o ! -f $targetFile ];then
echo "$regFile or $targetFile doesn't exist,please check it"
exit 1
fi
if [ -f $outFile ];then
rm $outFile
fi
while read curLine
do
grep $curLine $targetFile 》 $outFile
done < $regFile
echo "parse lines from $targetFile with $regFile to $outFile"
echo "==============\nfinished"