[英]Extract unique words from a file and print the numbers associated with it in the same line tab separated in linux
我的文件格式如下:
1: test
18: test
29: test
25: crazy
30: crazy
我想忽略大小寫並獲取文件中的唯一單詞及其各自的計數
所需的 output 應該是:
test: 1 18 29
crazy: 25 30
有人可以指導如何在 Linux/Bash 中做到這一點嗎?
有人可以指導如何在 Linux/Bash 中做到這一點嗎?
您可以使用 awk 的關聯數組來實現:
這將打印所需的 output。
awk -F':' '{a[$2]=a[$2]" " $1}END{for(i in a) print i": " a[i]}' input_file.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.