Processing 2 files with different field separators using awk

前端 未结 3 655
孤独总比滥情好
孤独总比滥情好 2020-12-15 14:15

Let\'s say I have 2 files :

$ cat file1
A:10
B:5
C:12

$ cat file2
100 A
50 B
42 C

I\'d like to have something like :

A 10          


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 14:45

    You need to get awk to re-split $0 after you change FS.

    You can do that with $0=$0 (for example).

    So {FS=" ";$0=$0;...} in your final block will do what you want.

    Though only doing that the first time you need to change FS will likely perform slightly better for large files.

提交回复
热议问题