How to grep for a complex String?

Hi,

I have a file hello.log which has the below entry

./logs/mymac/myserver.log:####<Jun 7, 2015 12:56:54 PM EDT> <myserver.my.bank.com> <mymac> <[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <1434640> <BEA-0900> <User user1 in security realm myrealm has had 5 invalid login attempts, locking account for 30 minutes.>

I tried to grep for the above string but it is not yielding any output.

x="./logs/mymac/myserver.log:####<Jun 7, 2015 12:56:54 PM EDT> <myserver.my.bank.com> <mymac> <[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <1434640> <BEA-0900> <User user1 in security realm myrealm has had 5 invalid login attempts, locking account for 30 minutes.>"
grep $x hello.log

Whats wrong with my Grep command ?

That's because $x is treated as a regex, seeing "[ACTIVE]" as bracket expression for one single character.
Use the fixed string option -F to grep .

1 Like

${x} should be enclosed in quotes. but it's also because you have special characters in the string like "[" and "]". Why do you have to such a long (exact) search string?

1 Like

Resolved !!