Linux Terminal: Finding number of lines longer than x

awk, bash, linux, terminal

Solution

If you want the number of lines that are longer than 80 characters (your question is missing the units), `grep` is a good candidate:

grep -c '.\{80\}'

So:

wget -qO - google.com | grep -c '.\{80\}'

outputs 6.

Problem

I come to you with a problem that has me stumped. I'm attempting to find the number of lines in a file (in this case, the html of a certain site) longer than x (which, in this case, is 80). For example: google.com has (by checking with wc -l) has 7 lines, two of which are longer than 80 (checking with awk '{print NF}'). I'm trying to find a way to check how many lines are longer than 80, and then outputting that number. My command so far looks like this: `wget -qO - google.com | awk '{print NF}' | sort -g` I was thinking of just counting which lines have values larger than 80, but I can't figure out the syntax for that. Perhaps 'awk'? Maybe I'm going about this the clumsiest way possible and have hit a wall for a reason. Thanks for the help! Edit: The unit of measurement are characters. The command should be able to find the number of lines with more than 80 characters in them.

Original source