Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the max value in a file using bash script?

Tags:

bash

I have a temperature.txt file, and I have to find the max value (the 5th one), and print the location (first 2 values), the date (3rd value) and time (4th value).

47.6498634,19.1404118,2002.05.18,08:32,-1
48.6498634,19.1404118,2003.05.18,09:32,28
49.6498634,19.1404118,2004.05.18,01:32,17
46.6498634,19.1404118,2005.05.18,02:32,15
45.6498634,19.1404118,2006.05.18,03:32,9
44.6498634,19.1404118,2007.05.18,04:32,31
43.6498634,19.1404118,2008.05.18,05:32,23
42.6498634,19.1404118,2009.05.18,06:32,13
like image 568
helpmeplease Avatar asked Jan 22 '26 16:01

helpmeplease


1 Answers

sort -t, -r -n -k5,5 temperature.txt | awk -F"," '{print $5,$1,$2,$3,$4}' | head -1

output

31 44.6498634 19.1404118 2007.05.18 04:32
like image 52
Ahmet Said Akbulut Avatar answered Jan 24 '26 08:01

Ahmet Said Akbulut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!