test program
test program

Reputation: 281

need to explain bash grep regular expression grep -E '(^|[^0-9.])'2 *.c

I'm confused with this grep command. I would like somebody to explain it for me.

For each digit i, search for the (nondigit)i sequence in the textd.sh)

grep -E '(^|[^0-9.])'i *.c

for i in 0 1 2 3 4 5 6 7 8 9; do
   grep -E '(^|[^0-9.])'$i *.c > lines_with_${i}
done

Upvotes: 1

Views: 599

Answers (1)

anubhava
anubhava

Reputation: 786011

This grep command:

grep -E '(^|[^0-9.])'$i *.c

Is matching digits 0, 1, 2, 3,.... in a loop.

While matching these digits it makes sure that digits are either at start (^) OR else there is a non-digit non-dot character before these digits ([^0-9.]).

So for example it will match:

abc 1
2
def5

and it won't match:

abc.1

Upvotes: 2

Related Questions