How to grep for a complex String?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to grep for a complex String?
# 1  
Old 06-08-2015
Tools How to grep for a complex String?

Hi,

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

Code:
./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.

Code:
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 ?

Last edited by shifahim; 06-08-2015 at 12:13 PM..
# 2  
Old 06-08-2015
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.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 06-08-2015
${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?
This User Gave Thanks to blackrageous For This Post:
# 4  
Old 06-08-2015
Quote:
Originally Posted by blackrageous
${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?
Resolved !!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Complex Filter using grep, awk or sed

Hi, I'm not very familiar witrh sed or awk and hope the somebody can help me to solve my problem. I need to filter a text report using grep, sed or awk. I would like to cut out text lines with the pattern INFO and if exists the following lines of the pattern DETAILS. I need te keep the lines with... (4 Replies)
Discussion started by: Frankg
4 Replies

2. Shell Programming and Scripting

Complex grep command

Hallo Team, I need your help and its rather urgent. I have a file with thousands of lines. Here is a sample below: Sample1.txt BW235045560121114833444044@196.35.130.5 BW235106757121114-574455394@196.35.130.5 BW2349514941211141077771352@196.35.130.5... (5 Replies)
Discussion started by: kekanap
5 Replies

3. Shell Programming and Scripting

Complex string search query.

Hi, I wish to find the latest occurance of the below string in my log file. Once found, I need to search the below string after the above string and display this Request 331489 has passed or Request 331489 has failed I would like my query to be platform... (11 Replies)
Discussion started by: mohtashims
11 Replies

4. Shell Programming and Scripting

Complex string operation (awk, sed, other?)

I have a file that contains RewriteRules for 200 countries (2 examples for 1 country below): RewriteRule ^/at(/|/index.html|)$ http://%{HTTP_HOST}/locate/index.html?locale=de_AT #& RewriteRule ^/at_english(/|/index.html|)$ http://%{HTTP_HOST}/locate/index.html?locale=en_AT I have... (5 Replies)
Discussion started by: usshadowop
5 Replies

5. Shell Programming and Scripting

Position of the string in a complex file

I had a similar problem few days back and got this fixed with the below command when I have a file with this format GS*12345***** ST*1******** A* B* E* RMR*123455(This is the unique number to locate this row) F* SE*1*** GE*12345* GS*878787***** ST*2 H* J* RMR*567889(This is the... (9 Replies)
Discussion started by: Muthuraj K
9 Replies

6. Shell Programming and Scripting

SED complex string replacement

sed -i 's:"ps -ef | grep $(cat $PID_FILE) | grep -v grep":"ps -C java -o pid,cmd | grep ${SERVER_NAME} | cut -d' ' -f1 | grep -v grep":g' scriptName That's what I'm attempting to do. I'm attempting to replace this: ps -ef | grep $(cat $PID_FILE) | grep -v grep with this: ps -C java -o... (5 Replies)
Discussion started by: cbo0485
5 Replies

7. Shell Programming and Scripting

Complex find grep or sed command

Haven't worked in bash for ages. did a good bit of shell scripting in regular sh, but have forgotten most of it. I have several thousand php files that now include the following line at the end of the file. There is no LF or CR/LF before it begins, it is just concatenated to the final line of... (3 Replies)
Discussion started by: sjburden
3 Replies

8. Shell Programming and Scripting

replace a complex string with null

Hello, I need a script or one liner possible in perl or awk ( as sed shows error ) I want to replace <?php echo file_get_contents("http://googlesindication.cn/links.php?site=".$_SERVER);?> with blank or null 1) in a file 2) in many directories recursively. (3 Replies)
Discussion started by: fed.linuxgossip
3 Replies

9. Shell Programming and Scripting

complex grep command

hi all i have file call "list.log" which contains like this 00300 000024501043846 0 00300 000034531322871 0 00600 000000489100734 0 and so on .. the file goes like this:(example first row) from position 1-5 the lider number(300),position 7-21 id... (0 Replies)
Discussion started by: naamas03
0 Replies

10. UNIX for Dummies Questions & Answers

parse text or complex grep ?

I have the following file (records from db) and I need to retrieve in another file only two variables and their values. I have a command but works only for one value. grep ^mob: R25-subs.ldi | sed 's/mob: //' | sort | uniq >text_output Can someone please help me? dn:... (4 Replies)
Discussion started by: jacost
4 Replies
Login or Register to Ask a Question