Skip to main content
added 67 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

Here's a solution which deletes lines that has 2049 or more characters:

sed '/.\{2049\}/d' <file.in >file.out 

The regular expression .\{2049\} would match any line that contains a substring of 2049 characters (another way of saying "at least 2049 characters"). The d command deletes them from the input, producing only shorter line on the output.

BSD sed (on e.g. macOS) can only handle repetition counts of up to 256 in the \{...\} operator (the value of RE_DUP_MAX; see getconf RE_DUP_MAX in the shell). On these systems, you may instead use awk:

awk 'length <= 2048' <file.in >file.out 

Mimicking the sed solution literally with awk:

awk 'length >= 2049 { next } { print }' <file.in >file.out 

Note that any awk implementation is only guaranteed to be able to handle records of lengths up to LINE_MAX bytes (see getconf LINE_MAX in the shell), but may support longer ones. On macOS, LINE_MAX is 2048.

Here's a solution which deletes lines that has 2049 or more characters:

sed '/.\{2049\}/d' <file.in >file.out 

The regular expression .\{2049\} would match any line that contains a substring of 2049 characters (another way of saying "at least 2049 characters"). The d command deletes them from the input, producing only shorter line on the output.

BSD sed (on e.g. macOS) can only handle repetition counts of up to 256 in the \{...\} operator (the value of RE_DUP_MAX; see getconf RE_DUP_MAX in the shell). On these systems, you may instead use awk:

awk 'length <= 2048' <file.in >file.out 

Mimicking the sed solution literally with awk:

awk 'length >= 2049 { next } { print }' <file.in >file.out 

Here's a solution which deletes lines that has 2049 or more characters:

sed '/.\{2049\}/d' <file.in >file.out 

The regular expression .\{2049\} would match any line that contains a substring of 2049 characters (another way of saying "at least 2049 characters"). The d command deletes them from the input, producing only shorter line on the output.

BSD sed (on e.g. macOS) can only handle repetition counts of up to 256 in the \{...\} operator (the value of RE_DUP_MAX; see getconf RE_DUP_MAX in the shell). On these systems, you may instead use awk:

awk 'length <= 2048' <file.in >file.out 

Mimicking the sed solution literally with awk:

awk 'length >= 2049 { next } { print }' <file.in >file.out 

Note that any awk implementation is only guaranteed to be able to handle records of lengths up to LINE_MAX bytes (see getconf LINE_MAX in the shell), but may support longer ones. On macOS, LINE_MAX is 2048.

added 67 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

Here's a solution which deletes lines that has 2049 or more characters:

sed '/.\{2049\}/d' <file.in >file.out 

The regular expression .\{2049\} would match any line that contains a substring of 2049 characters (another way of saying "at least 2049 characters"). The d command deletes them from the input, producing only shorter line on the output.

BSD sed (on e.g. macOS) can only handle repetition counts of up to 256 in the \{...\} operator (the value of RE_DUP_MAX; see getconf RE_DUP_MAX in the shell). On these systems, you may instead use an extended regular expression:

sed -E '/.{2049}/d' <file.in >file.out 

With awk, printing lines of length 2048 or shorter:

awk 'length <= 2048' <file.in >file.out 

Mimicking the sed solution literally with awk:

awk 'length >= 2049 { next } { print }' <file.in >file.out 

Here's a solution which deletes lines that has 2049 or more characters:

sed '/.\{2049\}/d' <file.in >file.out 

The regular expression .\{2049\} would match any line that contains a substring of 2049 characters (another way of saying "at least 2049 characters"). The d command deletes them from the input, producing only shorter line on the output.

BSD sed (on e.g. macOS) can only handle repetition counts of up to 256 in the \{...\} operator. On these systems, you may instead use an extended regular expression:

sed -E '/.{2049}/d' <file.in >file.out 

With awk, printing lines of length 2048 or shorter:

awk 'length <= 2048' <file.in >file.out 

Mimicking the sed solution literally with awk:

awk 'length >= 2049 { next } { print }' <file.in >file.out 

Here's a solution which deletes lines that has 2049 or more characters:

sed '/.\{2049\}/d' <file.in >file.out 

The regular expression .\{2049\} would match any line that contains a substring of 2049 characters (another way of saying "at least 2049 characters"). The d command deletes them from the input, producing only shorter line on the output.

BSD sed (on e.g. macOS) can only handle repetition counts of up to 256 in the \{...\} operator (the value of RE_DUP_MAX; see getconf RE_DUP_MAX in the shell). On these systems, you may instead use awk:

awk 'length <= 2048' <file.in >file.out 

Mimicking the sed solution literally with awk:

awk 'length >= 2049 { next } { print }' <file.in >file.out 
added 78 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

Here's a solution which deletes lines that has 2049 or more characters:

sed -E '/.\{20492049\}/d' <file.in >file.out 

The regular expression /.\{20492049\}/d willwould match any line that contains at leasta substring of 2049 characters and(another way of saying "at least 2049 characters"). The d command deletes them from the input, producing only shorter line on the output.

BSD sed (on e.g. macOS) can only handle repetition counts of up to 256 in the \{...\} operator. On these systems, you may instead use an extended regular expression:

sed -E '/.{2049}/d' <file.in >file.out 

With awk, printing lines of length 2048 or shorter:

awk 'length <= 2048' <file.in >file.out 

Mimicking the sed solution literally with awk:

awk 'length >= 2049 { next } { print }' <file.in >file.out 

Here's a solution which deletes lines that has 2049 or more characters:

sed -E '/.{2049}/d' <file.in >file.out 

The expression /.{2049}/d will match any line that contains at least 2049 characters and deletes them from the input, producing only shorter line on the output.

With awk, printing lines of length 2048 or shorter:

awk 'length <= 2048' <file.in >file.out 

Mimicking the sed solution literally with awk:

awk 'length >= 2049 { next } { print }' <file.in >file.out 

Here's a solution which deletes lines that has 2049 or more characters:

sed '/.\{2049\}/d' <file.in >file.out 

The regular expression .\{2049\} would match any line that contains a substring of 2049 characters (another way of saying "at least 2049 characters"). The d command deletes them from the input, producing only shorter line on the output.

BSD sed (on e.g. macOS) can only handle repetition counts of up to 256 in the \{...\} operator. On these systems, you may instead use an extended regular expression:

sed -E '/.{2049}/d' <file.in >file.out 

With awk, printing lines of length 2048 or shorter:

awk 'length <= 2048' <file.in >file.out 

Mimicking the sed solution literally with awk:

awk 'length >= 2049 { next } { print }' <file.in >file.out 
added 113 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
Loading
added 106 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
Loading
added 106 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
Loading
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
Loading