我有这样的CSV
Parameter Values,Count,% of Results
" david;dd@gmail.com;10300 "," 15 "," 50.0% "
" david;dd@gmail.com;12300 "," 15 "," 50.0% "
" davidk;dk@gmail.com;32300 "," 15 "," 50.0% "
" joe;joe@gmail.com;9200 "," 15 "," 50.0% "
" john;jj@gmail.com;1500 "," 15 "," 50.0% "
我想获得具有最高数值的行,在这种情况下为32300
我已经尝试过这个但它使用了几个命令
export max=$(awk -F, '{split($1,a,";"); print a[3] }' contestEntryTest.csv | tr -d ' "' | sort -nr | head -n 1) ; grep $max contestEntryTest.csv
我如何在较少的命令或一个命令中执行上述操作,一个经验更丰富的bash程序员将如何处理上述问题,仅用于学习体验。 干杯!
答案 0 :(得分:2)
如果文件是demo.csv,则可以使用sort,然后
sort -t ';' -k3 -n demo.cvs|tail -n 1
答案 1 :(得分:1)
一种纯粹的方法来做这个伎俩:
awk -F"[; ]" '($4>v){v=$4}END{print v}' FILE