I need a command to find the lines of a file that have 3 characters. I do the command wc -w field.txt
to list how many lines, but now I need to know the lines with 3 characters, exactly.
Advertisement
Answer
grep -c -E "^.{3}$" input.txt
This will count (-c) the number of lines which match the regex (-E) “^.{3}$”, which is “start of line, exactly three of anything, end of line”.