How to get those lines which have higher length among all the lines in the file using awk command [duplicate]
Clash 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.
linux awk
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.
 |Â
show 1 more comment
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.
linux awk
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
 |Â
show 1 more comment
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.
linux awk
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
linux awk
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
 |Â
show 1 more comment
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
 |Â
show 1 more comment
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
add a comment |Â
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!
add a comment |Â
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
add a comment |Â
up vote
0
down vote
awk ' if (length($0)>maxlength) maxlength=length($0); longest_line=$0; ;
END print longest_line; ' inputfile
add a comment |Â
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
awk ' if (length($0)>maxlength) maxlength=length($0); longest_line=$0; ;
END print longest_line; ' inputfile
answered Apr 28 at 15:35
Hauke Laging
53.2k1282130
53.2k1282130
add a comment |Â
add a comment |Â
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!
add a comment |Â
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!
add a comment |Â
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!
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!
edited Apr 28 at 15:50
answered Apr 28 at 15:38
steve
12.1k22048
12.1k22048
add a comment |Â
add a comment |Â
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