Skip to content

Find lines that contain greater than specified number of characters in Unix

When working with files in Unix, sometimes you need to find the files that are greater than a specified number of characters. Unix systems are often used as servers for applications in the corporate and enterprise. Some system interfaces require that files with data be sent from one server to another for processing. As a result, some files could be improperly formatted or could contain bad data which requires manual intervention.

awk 'length $(0)'>42  datafile.dat

In the command above, awk is the program used.

  • "$(0)" says to pull the entire line.
  • "42" is the number that you are filtering on. In the example, only lines that are greater than 42 characters will be displayed.
  • "datafile.dat" is the name of the file that you want to be checked.

Last update: 2015-10-30
Back to top