使用基于动态列作为变量的AWK比较2个文件,并打印差异A-B和B-A

问题描述 投票:0回答:1

档案1:

'SR'|'2017-09-01 00:19:13'|'+05:30'|'1A3LA7015L5O'|'5042449534546015801549'

'SR'|'2017-09-01 00:19:13'|'+05:30'|'1A3LA7015L5O'|'5042449534546015801677'

'SR'|'2017-09-01 00:19:13'|'+05:30'|'1A3LA7015L5Q'|'5042449536906016501541'

'SR'|'2017-09-01 00:19:20'|'+05:30'|'1A3LA7015L6I'|'5042449603146028701541'

文件2:

'SR'|'2017-09-01 00:19:13'|'+05:30'|'1A3LA7015L5Q'|'5042449536906016501541'

'SR'|'2017-09-01 00:19:20'|'+05:30'|'1A3LA7015L6I'|'5042449603146028701548'

我想要的OutPut是A-B和B-A

我尝试了下面的命令,但它似乎无法正常工作..

var1=5
awk -F "|" -v col="$var1" 'NR==FNR{a[$2];next} !($col in a)' File1 File2
awk -F "|" -v col="$var1" 'NR==FNR{a[$2];next} !($col in a)' File1 File2
bash shell compare
1个回答
-1
投票

我得到了解决方案,我正在做的错误是在{a[$2];next}中给出错误的列号

我必须比较第5列,它将像:

awk -F "|" -v col="$var1" 'NR==FNR{a[$5];next} !($col in a)' File1 File2
awk -F "|" -v col="$var1" 'NR==FNR{a[$5];next} !($col in a)' File1 File2
© www.soinside.com 2019 - 2024. All rights reserved.