Arun
Arun

Reputation: 1220

UNIX : Deleting all the lines containing string & number

I have a TXT files with lines of about 1 Million.

#Test.txt
zs272
zs273
zs277
zs278
zs282
zs285
zs288
zs289
zs298
zs300
zs7
zsa
zsag
zsani179yukkie
zsani182zaide
zsaqgiw
zsb86581
zsbguepqtkcn
zscazn
zscfhlsv
zscgxadrwijl
zsclions111yuen
zscwqtk
zscz
zsder
zsdfdgdgg

I wanted to delete the line which has the numbers and keeping only strings.

I tried,

grep -v '^[1-9]' Test.txt > 1_Test.txt

Couldn't get the desired result.

Expected output:

#1_Test.txt
    zsa
    zsag
    zsbguepqtkcn
    zscazn
    zscfhlsv
    zscgxadrwijl
    zscwqtk
    zscz
    zsder
    zsdfdgdgg

Upvotes: 0

Views: 51

Answers (3)

Firefly
Firefly

Reputation: 459

A solution in AWK!

awk '!/[0-9]+/{print}' file

Upvotes: 0

Cyrus
Cyrus

Reputation: 88999

sed '/[0-9]/d' file

If you want to edit your file "in place" use sed's option -i.


awk '!/[0-9]/' file

With bash:

while read -r line; do [[ ! $line =~ [0-9] ]] && printf "%s\n" "$line"; done < file

Upvotes: 2

Avinash Raj
Avinash Raj

Reputation: 174874

Just remove the start of the line anchor ^. ^[1-9] regex only matches the numbers 1-9 which exists at the start.

grep -v '[1-9]' Test.txt > 1_Test.txt

to work for all digits including 0.

grep -v '[0-9]' Test.txt > 1_Test.txt

Upvotes: 2

Related Questions