AWK script to print the line with the most fields

The script below displays the largest number of fields in twister.txt.

  awk '{if (NF > max) max = NF} END{print max}' twister.txt

My question is: how do you display the line that has the most fields in twister.txt.

+4
source share
1 answer
awk '{if (NF > max) {max = NF; line=$0}} END{print line}' twister.txt
+7
source

All Articles