LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find out the record number to which the max length belongs. (https://www.linuxquestions.org/questions/linux-newbie-8/find-out-the-record-number-to-which-the-max-length-belongs-4175469368/)

vaibhavs17 07-12-2013 02:14 AM

find out the record number to which the max length belongs.
 
Hi All,

I have a huge file, in which I have used below command to get the maximum record length in the file.

$ awk ' { if ( length > L ) { L=length} }END{ print L}' abc.csv
Output: 27151

Now, I would like to find out the record number to which this max length belongs.

For Example: Record# 850 has maximum length "27151"

Request you all to please have a look at this query.

Thanks,
Vaibhav

Ser Olmy 07-12-2013 02:22 AM

You could use the NR variable:
Code:

awk ' { if ( length > L ) { L=length ; LINE=NR } }END{ print "Record " LINE " has maximum length " L}' abc.csv

vaibhavs17 07-12-2013 02:34 AM

Thank you so much.

It worked for me


All times are GMT -5. The time now is 10:35 PM.