Reputation: 119
I am working on a shell script program where i am encountering @
and &
.
/bin/egrep -c '(@ sMAD:|& MAD :)' $File
Could you please tell me what egrep
is doing here. I understand that that we are getting the count of number of lines but this regex part is really confusing for me.
Upvotes: 0
Views: 191
Reputation: 290415
This is looking for either @ sMAD:
or & MAD :
in the file referred by $File
and counting how many lines satisfy this condition.
egrep -c '(@ sMAD:|& MAD :)' $File
^ ^^^^^^^ ^^^^^^^
| | or this
| either this
count lines that contain
$ cat a
hello
@ sMAD: can match & MAD : everything in the same line # match 1
& MAD : also does # match 2
but & MAD : is another thing # match 3
And now let's run the command:
$ egrep -c '(@ sMAD:|& MAD :)' a
3
Upvotes: 1