Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using grep to find string with brackets

Tags:

grep

unix

I have some problems with the grep command. I have the following two files in my folder:

test.dat:

fdf
bla(fd_bla_bla) =&
bdf bla

test2.dat

fd
fd
fij
d
bla(fdf)

fdjk
bla

Now I search for the bla having brackets after it with

grep 'bla(*)' *

but it just gives me the entry of the first file...Do you have an idea why?

like image 682
Guiste Avatar asked Sep 19 '13 08:09

Guiste


2 Answers

grep -F "bla(" 

This will tell grep to use special characters as a regular (Fixed) string.

like image 192
Payam Avatar answered Sep 16 '22 11:09

Payam


You need regular expressions to do that match.

egrep "bla\(.*\)" *.dat

will give the correct result.

like image 23
thefourtheye Avatar answered Sep 18 '22 11:09

thefourtheye