bash - Finding the lines with the lowest value in their third column given grep results - Ask Ubuntu
i have file consists of lines (other numbers included). part of output of
$ grep 1848 filename.csv
how can find top 5 lines have lowest third column in .csv
file given 1848 either in first or second column?
1848,2598,11.310694021273559 1848,2599,10.947275955606203 1848,2600,10.635270124233982 1848,2601,11.916564552040725 1848,2602,12.119810736845844 1848,2603,12.406661156256154 1848,2604,10.636275056472996 1848,2605,12.549890992708612 1848,2606,9.783802450936204 1848,2607,11.253697489670264 1848,2608,12.16385432290674 1848,2609,10.30355814063016 1848,2610,12.102525596913923 1848,2611,11.636595992818505 1848,2612,10.741178028606866 1848,2613,11.352414275107423 1848,2614,12.204860161717253 1848,2615,12.959915468475387 1848,2616,11.320652192610872
unfortunately 1848 appears in third column , need ignore that:
6687,8963,9.241848677632822 6687,9111,10.537325656184889 6687,9506,11.315629894841848
with gnu sort:
grep -e '(^1848|^[0-9]{4},1848)' file | sort -t, -k3n | head -n 5
(if first column may have less or more 4 digits, replace {4}
+
)
output:
1848,2606,9.783802450936204 1848,2609,10.30355814063016 1848,2600,10.635270124233982 1848,2604,10.636275056472996 1848,2612,10.741178028606866
Comments
Post a Comment