0

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).*

Jerry
  • 70,495
  • 13
  • 100
  • 144
  • For the look-ahead option, read [this](http://stackoverflow.com/questions/9197814/regex-lookahead-for-not-followed-by-in-grep). – Bernhard Barker Sep 13 '13 at 12:15

2 Answers2

2

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

^(37[^3]|3[^7]|[^3])[0-9]+$
Ibrahim Najjar
  • 19,178
  • 4
  • 69
  • 95
1

Use grep -v:

grep -v "^373" file

Using awk:

awk '!/^373/' file

Use grep -P (PCRE): Negative Lookahead

grep -P '^(?!373)' file
anubhava
  • 761,203
  • 64
  • 569
  • 643