+ -
当前位置:首页 → 问答吧 → 用for循环匹配两个文件问题

用for循环匹配两个文件问题

时间:2011-05-11

来源:互联网

文件3.txt对kaoqin.txt进行匹配,打印出匹配相同的行。这写了一个不知道什么地方出了问题请大家帮忙看一下。谢谢

fname="/home/zhuliang/3.txt"
fname2=/home/zhuliang/kaoqin.txt
for line in `cat $fname | grep -v "^#" | sed "/^\s*$/d"`
do
echo $line
#ybb=`sed -n '/$line/p' /home/zhuliang/bjkaoqin.txt`
ybb=`sed -n '/$line/p' $fname2`
echo $ybb
done

作者: ybbdnvjfd   发布时间: 2011-05-11

'$line'

作者: zooyo   发布时间: 2011-05-11

  1. grep -Ff 3.txt kaoqin.txt
复制代码

作者: lkk2003rty   发布时间: 2011-05-11

sed "/$line/"

把'改成"

作者: lkk2003rty   发布时间: 2011-05-11

多亏毛孩兄提醒,这么简单个事就没必要循环了吧。
  1. [root@localhost /test]# cat file
  2. 1
  3. 2
  4. 3
  5. 4
  6. [root@localhost /test]# cat file1
  7. 1
  8. 2
  9. 3
  10. 5
  11. [root@localhost /test]# comm -12 file file1
  12. 1
  13. 2
  14. 3
复制代码

作者: zooyo   发布时间: 2011-05-11