用awk,忽略casesensitve模式基于相同的模式总结行时 [英] Using awk, ignore casesensitve pattern when summarize lines based on the same pattern

查看:153
本文介绍了用awk,忽略casesensitve模式基于相同的模式总结行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用awk,我想基于相同的模式总结线条时忽略大小写sensitve模式。

Using awk, I would like to ignore case sensitve pattern when summarize lines based on the same pattern.

我有以下行(非常感谢安德烈(<一个href=\"http://stackoverflow.com/users/3476320/andrey\">http://stackoverflow.com/users/3476320/andrey)

I have the following line (big thanks to Andrey (http://stackoverflow.com/users/3476320/andrey)

awk '{n=$1;$1="";a[$0]+=n}END{for(i in a){print a[i], i}}' testing.txt

文件内容:

1 Used cars
12 Drivers
1 used cars
1 used  cars
14 drivers
2 Used Cars

实际产量

2  Used Cars
14  drivers
12  Drivers
2  used cars
1  Used cars

我需要有:

26 drivers/Drivers (doesn't matter)
5 used cars/Used Cars (doesn't matter)

感谢您!

推荐答案

也许是最简单的方法:

awk  '{$0=tolower($0);n=$1;$1="";a[$0]+=n}END{for(i in a){print a[i], i}}' file

这篇关于用awk,忽略casesensitve模式基于相同的模式总结行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆