Егор Грижук
Егор Грижук

Reputation: 25

How to exclude lines with regexp

I have a list of lines with numbers. Need to exclude from it all lines starting with 373.

For example my list is:

37322433151
37323175491
19376717186
79684480273
97246000252
37323175491
37323175491
40745108277

If i do cat ... | egrep '^[^373].*', then it excludes lines that start from 3 or 7, the output is

19376717186
97246000252
40745108277

Even if expression is ^[^(373)].*

I need too exclude only if line starts with 373. Could anyone tell me what expression should be used ?

I also tried '^(?!373).*

Upvotes: 0

Views: 145

Answers (2)

anubhava
anubhava

Reputation: 786146

Use grep -v:

grep -v "^373" file

Using awk:

awk '!/^373/' file

Use grep -P (PCRE): Negative Lookahead

grep -P '^(?!373)' file

Upvotes: 1

Ibrahim Najjar
Ibrahim Najjar

Reputation: 19423

If you wanna do it with a regex then you can try:

^(37[^3]|3[^7]|[^3])[0-9]+$

Upvotes: 2

Related Questions