I know this might be an old problem and it has been solved by many people; however, my version requires a little bit of twist.
So I have a file, I'll call it quest. For simiplicity here, it just have 4 entry:
John
Christina
Christine
Tom
Now, I want to use awk to get the longest name in this file and I want it to return both Christina and Christine.
This is what I have so far:
<quest awk '{ if(length>x) {x =length; y=$0} } END {print y}'
And it will just return Christina. I think it can be done with just one line but I am having troubles to come up with a clever way to do it. And I appreciate if you can help! And of course, I prefer a single line.
I prefer a single line- any program can be written in a single line so that's not a useful criteria for a solution. Also, using redirection for your input instead of specifying the file name as an awk arg removes your availability of FILENAME in the script and makes it harder to enhance in future if your requirements change in some ways.