How to remove all words written in capital letters ONLY (by using sed and/or awk)

Posted by Virtual_Lotos on Stack Overflow See other posts from Stack Overflow or by Virtual_Lotos
Published on 2013-11-05T15:48:12Z Indexed on 2013/11/05 15:53 UTC
Read the original article Hit count: 159

Filed under:
|
|
|

I am trying to delete all words written in capital letters only by using sed:

sed -r "s/\b[A-Z]\w*\s*//g" < file1 > file2

But this solution capture all the words starting with capital letters and delete them (this in not the goal).

Here's an example:

file1 content:

AAAAAAAAAAAA
BBbbbbb
AbAbAbAb
aaaaaBBBBB
AAAAAA BBBBBB
A1-B1
a1-b1
A1-b1 AA
AAAAA BBBBB AAAAA
Abbbb AAA
AAAAA AAAABB
Abbbb Baaaa Aaaaa AB
AAAAAA1
BBBBBBb
AAAAAA 1
BBBBBB b

Result should be like this (file2 content):

BBbbbbb
AbAbAbAb
aaaaaBBBBB
A1-B1
a1-b1
A1-b1 AA
Abbbb AAA
Abbbb Baaaa Aaaaa AB
AAAAAA1
BBBBBBb
AAAAAA 1
BBBBBB b

Each line of at least one digit or one lowercase letter should remain intact (should not be deleted).

© Stack Overflow or respective owner

Related posts about bash

Related posts about shell