helpmeplease
helpmeplease

Reputation: 59

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

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

Upvotes: 3

Views: 807

Answers (1)

Ahmet Said Akbulut
Ahmet Said Akbulut

Reputation: 424

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

Upvotes: 2

Related Questions