How to get those lines which have higher length among all the lines in the file using awk command [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite













This question already has an answer here:



  • How to print the longest line in a file?

    9 answers



I want that line from the file which have highest length among all the lines using awk command.







share|improve this question













marked as duplicate by Sundeep, G-Man, Jesse_b, roaima, Community♦ Apr 29 at 7:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • What is your definition of "highest length"? You say you want multiple lines, does that mean like "Top 5 highest length"?
    – Jesse_b
    Apr 28 at 14:33










  • I read it as “if there’s a tie, all the longest lines”
    – Jeff Schaller
    Apr 28 at 14:34










  • No I only want that "line which has higher length among all the lines" and "if there is tie then all the longest line"
    – Shah Honey
    Apr 28 at 15:24











  • "higher" is a comparative word, and as such needs qualification. Do you mean "highest", i.e. the "longest line or joint-longest lines"?
    – roaima
    Apr 28 at 15:33







  • 1




    there are other solutions in that question that handle more than one line with max length... in gawk as well as other tools
    – Sundeep
    Apr 28 at 16:20














up vote
1
down vote

favorite













This question already has an answer here:



  • How to print the longest line in a file?

    9 answers



I want that line from the file which have highest length among all the lines using awk command.







share|improve this question













marked as duplicate by Sundeep, G-Man, Jesse_b, roaima, Community♦ Apr 29 at 7:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • What is your definition of "highest length"? You say you want multiple lines, does that mean like "Top 5 highest length"?
    – Jesse_b
    Apr 28 at 14:33










  • I read it as “if there’s a tie, all the longest lines”
    – Jeff Schaller
    Apr 28 at 14:34










  • No I only want that "line which has higher length among all the lines" and "if there is tie then all the longest line"
    – Shah Honey
    Apr 28 at 15:24











  • "higher" is a comparative word, and as such needs qualification. Do you mean "highest", i.e. the "longest line or joint-longest lines"?
    – roaima
    Apr 28 at 15:33







  • 1




    there are other solutions in that question that handle more than one line with max length... in gawk as well as other tools
    – Sundeep
    Apr 28 at 16:20












up vote
1
down vote

favorite









up vote
1
down vote

favorite












This question already has an answer here:



  • How to print the longest line in a file?

    9 answers



I want that line from the file which have highest length among all the lines using awk command.







share|improve this question














This question already has an answer here:



  • How to print the longest line in a file?

    9 answers



I want that line from the file which have highest length among all the lines using awk command.





This question already has an answer here:



  • How to print the longest line in a file?

    9 answers









share|improve this question












share|improve this question




share|improve this question








edited Apr 28 at 15:36









Hauke Laging

53.2k1282130




53.2k1282130









asked Apr 28 at 14:25









Shah Honey

173




173




marked as duplicate by Sundeep, G-Man, Jesse_b, roaima, Community♦ Apr 29 at 7:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Sundeep, G-Man, Jesse_b, roaima, Community♦ Apr 29 at 7:36


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • What is your definition of "highest length"? You say you want multiple lines, does that mean like "Top 5 highest length"?
    – Jesse_b
    Apr 28 at 14:33










  • I read it as “if there’s a tie, all the longest lines”
    – Jeff Schaller
    Apr 28 at 14:34










  • No I only want that "line which has higher length among all the lines" and "if there is tie then all the longest line"
    – Shah Honey
    Apr 28 at 15:24











  • "higher" is a comparative word, and as such needs qualification. Do you mean "highest", i.e. the "longest line or joint-longest lines"?
    – roaima
    Apr 28 at 15:33







  • 1




    there are other solutions in that question that handle more than one line with max length... in gawk as well as other tools
    – Sundeep
    Apr 28 at 16:20
















  • What is your definition of "highest length"? You say you want multiple lines, does that mean like "Top 5 highest length"?
    – Jesse_b
    Apr 28 at 14:33










  • I read it as “if there’s a tie, all the longest lines”
    – Jeff Schaller
    Apr 28 at 14:34










  • No I only want that "line which has higher length among all the lines" and "if there is tie then all the longest line"
    – Shah Honey
    Apr 28 at 15:24











  • "higher" is a comparative word, and as such needs qualification. Do you mean "highest", i.e. the "longest line or joint-longest lines"?
    – roaima
    Apr 28 at 15:33







  • 1




    there are other solutions in that question that handle more than one line with max length... in gawk as well as other tools
    – Sundeep
    Apr 28 at 16:20















What is your definition of "highest length"? You say you want multiple lines, does that mean like "Top 5 highest length"?
– Jesse_b
Apr 28 at 14:33




What is your definition of "highest length"? You say you want multiple lines, does that mean like "Top 5 highest length"?
– Jesse_b
Apr 28 at 14:33












I read it as “if there’s a tie, all the longest lines”
– Jeff Schaller
Apr 28 at 14:34




I read it as “if there’s a tie, all the longest lines”
– Jeff Schaller
Apr 28 at 14:34












No I only want that "line which has higher length among all the lines" and "if there is tie then all the longest line"
– Shah Honey
Apr 28 at 15:24





No I only want that "line which has higher length among all the lines" and "if there is tie then all the longest line"
– Shah Honey
Apr 28 at 15:24













"higher" is a comparative word, and as such needs qualification. Do you mean "highest", i.e. the "longest line or joint-longest lines"?
– roaima
Apr 28 at 15:33





"higher" is a comparative word, and as such needs qualification. Do you mean "highest", i.e. the "longest line or joint-longest lines"?
– roaima
Apr 28 at 15:33





1




1




there are other solutions in that question that handle more than one line with max length... in gawk as well as other tools
– Sundeep
Apr 28 at 16:20




there are other solutions in that question that handle more than one line with max length... in gawk as well as other tools
– Sundeep
Apr 28 at 16:20










2 Answers
2






active

oldest

votes

















up vote
0
down vote













awk ' if (length($0)>maxlength) maxlength=length($0); longest_line=$0; ;
END print longest_line; ' inputfile





share|improve this answer




























    up vote
    0
    down vote













    Check length of line (if no arguments passed to the length function it uses $0, the whole line).



    Where length is greater than variable x, set x to the length. And set variable a to the contents of the line.



    Finally, on reaching end of file, print the contents of variable a.



    awk 'length>xx=length;a=$0ENDprint a' inputfile


    Try it online!






    share|improve this answer






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      awk ' if (length($0)>maxlength) maxlength=length($0); longest_line=$0; ;
      END print longest_line; ' inputfile





      share|improve this answer

























        up vote
        0
        down vote













        awk ' if (length($0)>maxlength) maxlength=length($0); longest_line=$0; ;
        END print longest_line; ' inputfile





        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          awk ' if (length($0)>maxlength) maxlength=length($0); longest_line=$0; ;
          END print longest_line; ' inputfile





          share|improve this answer













          awk ' if (length($0)>maxlength) maxlength=length($0); longest_line=$0; ;
          END print longest_line; ' inputfile






          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Apr 28 at 15:35









          Hauke Laging

          53.2k1282130




          53.2k1282130






















              up vote
              0
              down vote













              Check length of line (if no arguments passed to the length function it uses $0, the whole line).



              Where length is greater than variable x, set x to the length. And set variable a to the contents of the line.



              Finally, on reaching end of file, print the contents of variable a.



              awk 'length>xx=length;a=$0ENDprint a' inputfile


              Try it online!






              share|improve this answer



























                up vote
                0
                down vote













                Check length of line (if no arguments passed to the length function it uses $0, the whole line).



                Where length is greater than variable x, set x to the length. And set variable a to the contents of the line.



                Finally, on reaching end of file, print the contents of variable a.



                awk 'length>xx=length;a=$0ENDprint a' inputfile


                Try it online!






                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Check length of line (if no arguments passed to the length function it uses $0, the whole line).



                  Where length is greater than variable x, set x to the length. And set variable a to the contents of the line.



                  Finally, on reaching end of file, print the contents of variable a.



                  awk 'length>xx=length;a=$0ENDprint a' inputfile


                  Try it online!






                  share|improve this answer















                  Check length of line (if no arguments passed to the length function it uses $0, the whole line).



                  Where length is greater than variable x, set x to the length. And set variable a to the contents of the line.



                  Finally, on reaching end of file, print the contents of variable a.



                  awk 'length>xx=length;a=$0ENDprint a' inputfile


                  Try it online!







                  share|improve this answer















                  share|improve this answer



                  share|improve this answer








                  edited Apr 28 at 15:50


























                  answered Apr 28 at 15:38









                  steve

                  12.1k22048




                  12.1k22048












                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay