May 3, 2010 #1 PoxKing Technical User Joined May 3, 2010 Messages 4 Location GB There is a file that contains: MFT 90 FFF 87 SIA 76 SSS 94 This file can be called Data.txt I'd like to know how to use awk to compare the second fields and return the line with the biggest number. Many thanks.
There is a file that contains: MFT 90 FFF 87 SIA 76 SSS 94 This file can be called Data.txt I'd like to know how to use awk to compare the second fields and return the line with the biggest number. Many thanks.
May 3, 2010 #2 PHV MIS Joined Nov 8, 2002 Messages 53,708 Location FR awk '$2>m{m=$2;x=$0}END{print x}' Data.txt Hope This Helps, PH. FAQ219-2884 FAQ181-2886 Upvote 0 Downvote
May 3, 2010 Thread starter #3 PoxKing Technical User Joined May 3, 2010 Messages 4 Location GB Thanks a lot even you did it wrong I added if and it worked. Upvote 0 Downvote
May 3, 2010 #4 PHV MIS Joined Nov 8, 2002 Messages 53,708 Location FR you did it wrong Really ? I added if Where ? Upvote 0 Downvote
May 3, 2010 Thread starter #5 PoxKing Technical User Joined May 3, 2010 Messages 4 Location GB It was not totally really wrong, but needed 'if' awk {if ($2>m) {m=$2;x=$0} END{print x}' Data.txt the previous command didn't work. Upvote 0 Downvote
It was not totally really wrong, but needed 'if' awk {if ($2>m) {m=$2;x=$0} END{print x}' Data.txt the previous command didn't work.
May 3, 2010 #6 PHV MIS Joined Nov 8, 2002 Messages 53,708 Location FR I highly doubt that your posted code don't raise an error ... Upvote 0 Downvote
May 3, 2010 Thread starter #7 PoxKing Technical User Joined May 3, 2010 Messages 4 Location GB awk {if ($2>m) {m=$2;x=$0}} END{print x}' Data.txt it works, tested. Upvote 0 Downvote
May 3, 2010 #8 PHV MIS Joined Nov 8, 2002 Messages 53,708 Location FR it works, tested Again, not as posted. It's why I believe you didn't test my exact code. Upvote 0 Downvote
May 3, 2010 #9 Annihilannic MIS Joined Jun 22, 2000 Messages 6,317 Location AU No if is required because there is an implicit if before every expression { code block } pair. Annihilannic. Upvote 0 Downvote
No if is required because there is an implicit if before every expression { code block } pair. Annihilannic.