Rouki
Rouki

Reputation: 2345

Grep examples - can't understand

Given the following commands:

ls | grep ^b[^b]*b[^b]

ls | grep ^b[^b]*b[^b]*

I know that ^ marks the start of the line, but can anyone give me a brief explanation about these commands? what do they do? (Step by step)

thanks!

Upvotes: 1

Views: 226

Answers (2)

sehe
sehe

Reputation: 393134

^ can mean two things:

  • mark the beginning of a line
  • or it negates the character set (whithin [])

So, it means:

  • lines starting with 'b'
  • matching any (0+) characters Other than 'b'
  • matching another 'b'
  • followed by something not-'b' (or nothing at all)

It will match

bb
bzzzzzb
bzzzzzbzzzzzzz

but not

zzzzbb
bzzzzzxzzzzzz

Upvotes: 4

Vijay
Vijay

Reputation: 67231

1)starts with b and name continues with a 0 or more characters which are not b and then b and then continues with a character which is not b

2)starts with b and name continues with a 0 or more characters which are not b and then b and then continues with 0 or more characters which are not b

Upvotes: 0

Related Questions