为什么执行awk命令导出文件为空 awk -F'[/,]' 'ARGIND==1{a[$0]}ARGIND>1{if ($2 in a)print $0}' b a >c
文件a:10/05766798607,11/20050325191329,29/0.1,14/0576679860710/05767158557,11/200503251...
文件a:
10/05766798607,11/20050325191329,29/0.1,14/05766798607
10/05767158557,11/20050325191329,29/0.08,14/05767158557
文件b:
05766798607
05766798608
05766798609
通过文件a和文件b对比,导出这样的文件出来.
10/05766798607,11/20050325191329,29/0.1,14/05766798607
正确答案应该:
方法一: awk -F'[/,]' 'ARGIND==1{a[$0]}ARGIND>1{if ($2 in a)print $0}' b a >c
方法二: awk -F'[/,]' 'NR==FNR{a[$0]}NR>FNR{if ($2 in a) print $0}' b a >c
root@VirtualBox:/home/susz# more b
05766798607
05766798608
05766798609
root@VirtualBox:/home/susz# more a
10/05766798607,11/20050325191329,29/0.1,14/05766798607
10/05767158557,11/20050325191329,29/0.08,14/05767158557
root@susz-VirtualBox:/home/susz# awk -F'[/,]' 'ARGIND==1{a[$0]}ARGIND>1{if ($2 in a)print $0}' b a >c
root@susz-VirtualBox:/home/susz# more c
root@susz-VirtualBox:/home/susz#没有输出文件,为什么? 展开
10/05766798607,11/20050325191329,29/0.1,14/05766798607
10/05767158557,11/20050325191329,29/0.08,14/05767158557
文件b:
05766798607
05766798608
05766798609
通过文件a和文件b对比,导出这样的文件出来.
10/05766798607,11/20050325191329,29/0.1,14/05766798607
正确答案应该:
方法一: awk -F'[/,]' 'ARGIND==1{a[$0]}ARGIND>1{if ($2 in a)print $0}' b a >c
方法二: awk -F'[/,]' 'NR==FNR{a[$0]}NR>FNR{if ($2 in a) print $0}' b a >c
root@VirtualBox:/home/susz# more b
05766798607
05766798608
05766798609
root@VirtualBox:/home/susz# more a
10/05766798607,11/20050325191329,29/0.1,14/05766798607
10/05767158557,11/20050325191329,29/0.08,14/05767158557
root@susz-VirtualBox:/home/susz# awk -F'[/,]' 'ARGIND==1{a[$0]}ARGIND>1{if ($2 in a)print $0}' b a >c
root@susz-VirtualBox:/home/susz# more c
root@susz-VirtualBox:/home/susz#没有输出文件,为什么? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询