如何根据模式用底部字符串替换文件顶部的字符串
how do I replace the string from the top of the file with the bottom string based on pattern
我有以下文件:
石油,36262
阿图尔,946034
亚历克斯,12345
亚历克斯,99999
阿图尔,111111111
我需要的是根据第一列作为主键将上面的字符串替换为底部的字符串,所以最后它看起来像:
石油,36262
亚历克斯,99999
阿图尔,111111111
第一列可以包含 space 或数字。
谢谢
这是一种方法:
$ awk -F, '{a[]=} END{for (name in a)print name","a[name]}' file
alex,99999
artur,111111111
petro,36262
这些行以任意顺序出现。如果您有首选订单,则需要一些额外的代码。
我有以下文件:
石油,36262 阿图尔,946034 亚历克斯,12345 亚历克斯,99999 阿图尔,111111111
我需要的是根据第一列作为主键将上面的字符串替换为底部的字符串,所以最后它看起来像:
石油,36262 亚历克斯,99999 阿图尔,111111111
第一列可以包含 space 或数字。
谢谢
这是一种方法:
$ awk -F, '{a[]=} END{for (name in a)print name","a[name]}' file
alex,99999
artur,111111111
petro,36262
这些行以任意顺序出现。如果您有首选订单,则需要一些额外的代码。