May 3, 2010 #1 PoxKing Technical User May 3, 2010 4 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 Nov 8, 2002 53,708 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 May 3, 2010 4 GB Thanks a lot even you did it wrong I added if and it worked. Upvote 0 Downvote
May 3, 2010 #4 PHV MIS Nov 8, 2002 53,708 FR you did it wrong Really ? I added if Where ? Upvote 0 Downvote
May 3, 2010 Thread starter #5 PoxKing Technical User May 3, 2010 4 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 Nov 8, 2002 53,708 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 May 3, 2010 4 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 Nov 8, 2002 53,708 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 Jun 22, 2000 6,317 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.