user1899415
user1899415

Reputation: 3125

Unix: how to delete lines that contain more than N consecutive upper case characters?

I want to delete lines in a file with 3 or more consecutive upper case characters.

Input:

ABBOTT FLORIST MIAMI BEACH
Abbott Lake Loop
Abbott Philip DDS

Output:

Abbot Lake Loop

I tried sed 's/[A-Z]{3}/g' infile but does not give me desired results. Any help?

Upvotes: 0

Views: 386

Answers (3)

NeronLeVelu
NeronLeVelu

Reputation: 10039

sed -n '/[A-Z]\{3,\}/ p' infile

print only line with at least 3 upper letter together

your sed (sed 's/[A-Z]{3}/g' infile) is a partial sed action

  • create a substitution of something, so print a least an empty line for every line of input
  • you select a Upper case char followed by {3}litteraly, missing the escape \ before {
  • you select a pattern but dont give any substitution result. s/selectpattern/resultpattern/option

Upvotes: 0

jaypal singh
jaypal singh

Reputation: 77105

Here is another alternate using awk:

$ awk '/[A-Z]{3,}/{next}1' file
Abbott Lake Loop 

Upvotes: 2

Guru
Guru

Reputation: 16994

One way using GNU sed:

sed -r '/[A-Z]{3,}/d' file

grep can also be used :

grep -vE "[A-Z]{3,}" file

Upvotes: 3

Related Questions