linux awk提取列用tab键分割,Linux:如果在linux中使用AWK的選項卡分隔文件的值不匹配時,如何打印行號和列號...

Compare File 1 vs File2 and print line no. for difference record and column no of difference present in file2.

比較文件1與文件2和打印行號。對於差異記錄和file2中存在的差異列。

In file1:

在file1中:

User_ID First_name Last_name Address Postal_code

User_1 fistname Lastname 35, Park Lake, California 32068

user2 Johnny Depp 32, Park Lake, California

user3 Tom Cruise 5322 Otter Lane Middleberge 32907

user4 Leonardo DiCaprio Half-Way Pond, Georgetown 1230

user5 Sylvester Stallone 6762,33 Ave N,St. Petersburg 33710

user6 Srleo Stallone 6762,33 Ave N,St. Petersburg 33700

and

In file2:

在file2中:

User_ID First_name Last_name Address Postal_code

User_1 fistname Lastname 35, Park Lake, California 32068

user2 Johnny Depp 32, NEW Street, California 96206

user30 Tom Cruise 5322 Otter Lane Middleberge 32907

user4 Leonardo DiCaprio' Half-Way Pond, Georgetown 00000

user5 Sylvester Stallone 6762,33 Ave N,St. Petersburg 33710

user7 Nicolas Cage 55010

user6 Srleo Stallone 6762,33 Ave N,St. Petersburg 33700

**Expected Result:-

**預期結果:-

Difference in file2 is line number followed by column number (where the values do not match)**

file2的差異是行號,后跟列號(值不匹配)**

Line No. 2 COLUMN NO- 4,5

Line No. 3 COLUMN NO-1

Line No. 4 COLUMN NO 3,5

Line No. 5 COLUNN NO 5

Line No. 6 COLUMN NO 1,2,3,4,5

Note: File size to be compare is in GB and File is tab separated and has more than 400 tab separated column.

注意:要比較的文件大小以GB為單位,文件以制表符分隔,並且具有超過400個制表符分隔列。

I am using-

我在用-

awk 'NR==FNR{Arr[$0]++;next}!($0 in Arr){print FNR}' file1 file2

However, it gives me the line numbers and not the Column Numbers

但是,它給出了行號而不是列號

1 个解决方案

#1

2

this should do, however doesn't match your expected result

這應該做,但是不符合您的預期結果

paste f1 f2 |

awk -F'\t' 'NR==1 {n=NF/2}

{for(i=1;i<=n;i++)

if($i!=$(i+n))

{c=c s i; s=","}

if(c)

{print "Line No. " NR-1 " COLUMN NO " c;

c="";s=""}}'

Line No. 2 COLUMN NO 4,5

Line No. 3 COLUMN NO 1

Line No. 4 COLUMN NO 3,5

Line No. 6 COLUMN NO 1,2,3,4,5

Line No. 7 COLUMN NO 1,2,3,4,5

either you're not comparing line by line or some following some other unwritten spec.

要么你不是逐行比較,要么是一些其他不成文的規范。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值