简体   繁体   English

在Windows中使用Cygwin排序文件

[英]Sorting a file with Cygwin in Windows

I have a file with thousands of beer reviews that I need to sort. 我有一个文件,其中包含我需要排序的数千条啤酒评论。 Each beer review looks like this: 每个啤酒评论看起来像这样:

beer/name: John Harvards Simcoe IPA
beer/beerID: 63836
beer/brewerID: 8481
beer/ABV: 5.4
beer/style: India Pale Ale (ITA)
review/appearance: 4/5
review/aroma: 6/10
review/palate: 3/5
review/taste: 6/10
review/overall: 13/20
review/time: 11575857200

I need to sort top 10 beers with the highest number of reviews. 我需要对评论数最高的前10位啤酒进行排序。 The beer identifier 'beer/name'. 啤酒标识符“啤酒/名称”。

Sounds like a homework, but anyway (I like the beer), this is an starter : 听起来像是一项家庭作业,但无论如何(我喜欢啤酒),这是一个 启动器

awk -F'[ /]' -v note=20 '
    /^beer\/name:/{$1=$2="";beer=$0}
    /^review/ && !/review\/time/{arr[beer]+=$3/$4; count++}
    END{for (a in arr) print a, arr[a]*note/count "/" note}
' beers.txt

It's easy from this to pipe the output to the sort & head command to sort a specific column & display N lines from the top respectively. 可以很容易地将输出传递给sorthead命令,以对特定的列进行排序,并分别从顶部显示N行。 (Or use awk itself, but it's harder...) (或者使用awk本身,但这很难...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM