Which command to search the file myfile for all occurances of string containing at least five characters, where character number 2 and 5 are ‘a’ and character number 3 is NOT ‘b’ ?

You want to search the file myfile for all occurances of string containing at least five characters,
where character number 2 and 5 are ‘a’ and character number 3 is NOT ‘b’.

Which command would you use?

You want to search the file myfile for all occurances of string containing at least five characters,
where character number 2 and 5 are ‘a’ and character number 3 is NOT ‘b’.

Which command would you use?

A.
grep a*^b*a myfile

B.
grep .a[^b].a myfile

C.
grep .[a].*.[a] myfile

D.
grep .a*^b..a myfile

Explanation/Reference:
A) since ^ without brackets indicates beginning of line, this regex would search for lines where any count of ‘a’ come before the start of the line
C) would find every combination like xabax
D) has the same problem as A



Leave a Reply 0

Your email address will not be published. Required fields are marked *