0

I have a file with numbers and words and I need to get only numbers:

File:

ASCII
Baron
Cbada
Dbadal
ebadals
Abadessa
Abadesses
Abadia
Abarca
jbarques
Zbat
Abdalong
Rbdies
Abdon
Abel
ibelard
Abell
Abella
Abellan
Abellana
quebellanes
370
410
1
12
123
1234
12345
123456
1234567
12345678
123456789
87654321
7654321
654321
54321
4321
321
21
937895432
938965432
930895432
913769890
916767800
91676780
977895432

if I do egrep "\b[^9][0-9]+" I do not get the one starting with 97.

And obviously "\b[^91][0-9]+" don't show the ones starting with 9 or 1.

If I do egrep -v "\b9[13]" I get the words, which I don't want...

3 Answers3

2

Yes, thanks to the comment of @QuickishFM I came up with this solution:

egrep -v "\b9[13]" file | egrep "[0-9]+"

Thanks

1

Try this:

<file egrep '^[0-9]+' | egrep -v '^9(1|3)'

or

egrep -v '^9(1|3)|[[:alpha:]]' file

-v, --invert-match
       Invert the sense of matching, to select non-matching lines.

Freddy
  • 1,495
0

Using grep -P (PCRE) with a negative lookahead to make sure lines don't begin with 91 or 93:

grep -P  '^(?!9[13])[0-9]+$' file
370
410
1
12
123
1234
12345
123456
1234567
12345678
123456789
87654321
7654321
654321
54321
4321
321
21
977895432
Toto
  • 19,304