Give me a Linux pipeline to output the 10 longest lines in a file. #Linux #DFIR #CommandLine #Trivia

Nov 16, 2022 · 2:22 PM UTC

3
1
Yesterday's Linux DFIR command line trivia asked for a Linux pipeline to output the 10 longest lines in a file. You're going to need a loop to do this. You could go with an explicit loop, like 🐘secshoggoth@infosec.exchange did: cat filename |… infosec.exchange/@hal_pomera…
1
Replying to @hal_pomeranz
similar answer but I like awk. awk '{print length, $0}' FILENAME | sort -n | tail -10 | cut -d ' ' -f2-
2
Replying to @hal_pomeranz
cat FILE | while read -r line; do WC=`echo $line | wc -c`; echo "$WC $line"; done | sort -nr | head -10 | cut -d ' ' -f2- remove the cut if you want to see the line lengths
1