Skip to main content
Became Hot Network Question
Reformulate title and question to make the intention easier to understand
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

Grep, if the line contains X characters Select lines based on length

Line 1: Length 300 CharactersI would like to use grep or another suitable tool to look for (and print) lines not based on some pattern, but on the length.

Line 2: Length 120 CharactersAssume I have a file that contains two lines, where

  • Line 1: length = 300 characters
  • Line 2: length = 120 characters

Output: Only LineI am looking for a command that would only output line 2.

Grep, if the line contains X characters

Line 1: Length 300 Characters

Line 2: Length 120 Characters

Output: Only Line 2.

Select lines based on length

I would like to use grep or another suitable tool to look for (and print) lines not based on some pattern, but on the length.

Assume I have a file that contains two lines, where

  • Line 1: length = 300 characters
  • Line 2: length = 120 characters

I am looking for a command that would only output line 2.

Source Link

Grep, if the line contains X characters

Line 1: Length 300 Characters

Line 2: Length 120 Characters

Output: Only Line 2.