special grep on log files... puzzling me.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting special grep on log files... puzzling me.
# 1  
Old 06-10-2010
special grep on log files... puzzling me.

Okay, guys, I've got one:

I've got a script that formats all of the messages in a log file.
It works on a completely verbose method.
I'm trying to write a filter that will search for a bunch of case-insensitive strings, but also, always print the first 2 lines.

Here's the egrep part:

Code:
egrep -i '(rec:|key32|hosp|dkey|fac|mcare|patkey|\~\~\~|-----)'

The input looks like:
Code:
A: |/qatools/users/droberts/logs/test_regr/xrdrflat9b/rdrflat9b_disch.qa|
B: |/qatools/users/droberts/logs/test_regr/xrdrflat9b/rdrflat9b_disch.csv|
A: |00003800001 ,H000109241199000000 ,110168,000109241199,08/01/2008 . . . |
B: |00003800001 ,H000109241199000000 ,110168,000109241199        ,08 . . . |
Rec:2                  rdrflat9b_disch.qa       rdrflat9b_disch.csv
---------------------- ------------------------ ------------------------
 1-COHOSP              |00003800001           | |00003800001           |
 2-DKEY                |H000109241199000000   | |H000109241199000000   |
 3-MC                  |110168                | |110168                |
 4-DKEY                |000109241199          | |000109241199          |
2-IN_DDAT             |08/02/2008            | |08/02/2008            |
23-IN_LOS              |001                   | |000001                |
24-ACOD                |3                     | |3                     |
25-AFRO                |0                     | |0                     |
26-ER                  |0                     | |1                     | <~~~<<
27-ACOD                |3                     | |3                     |
28-ETHNICITY           |0                     | |0                     |
29-POA_AVAIL           |1                     | |000001                |
30-BDAT                |250809                | |250809                |
31-PHYS                |007057                | |00000007057           |
====================== ======================== ========================

I've banged my head against various combinations of sed, nawk, etc... and I can't get it work, when suddenly I remembered the host of experts watching this site! HELP! :-)

Thanks!
# 2  
Old 06-10-2010
Would using NR < 3 in awk help fetching the 1st 2 lines? I am not sure if I completely understood since that would seem to be too easy Smilie
# 3  
Old 06-10-2010
Am I missing something?

Code:
{ 
  head -2
  egrep -i '(rec:|key32|hosp|fac|mcare|(d|pat)key|~{3}|-{5})'
  } < infile

Use /usr/xpg4/bin/egrep (or better grep -E) on Solaris.
# 4  
Old 06-10-2010
Nailed it, Radoulov.

I did have to use your recommended version of egrep, but this worked with the /usr/bin/egrep one also:

Code:
egrep -i '(rec:|key32|hosp|fac|mcare|(d|pat)key|\~\~\~|=====)'

I wasn't familiar with that shell { ... commands ... } construct.

thanks a lot!!

---------- Post updated at 06:34 AM ---------- Previous update was at 06:31 AM ----------

hmmm.... plain ol' subshell works also.... I'm surprised.

One slight problem. I'm seeing this oddball line show up in the output:

Code:
           | |0                     | <~~~<<

What in the world?!?!

---------- Post updated at 06:38 AM ---------- Previous update was at 06:34 AM ----------

Hmmm... it seems to be skipping the first logical block.
In fact the first logical 2 blocks....

So.... not working. Too fancy?

---------- Post updated at 06:43 AM ---------- Previous update was at 06:38 AM ----------

Okay, guys. Finally hacked an easy kludge:

Code:
sed -e '1,2s/^/FROGS/' |
  egrep -i '(FROGS|rec:|key32|hosp|dkey|fac|mcare|patkey|\~\~\~|-----)' |
  sed -e 's/FROGS//g'

print -- ---------------------- ------------------------ ------------------------

# 5  
Old 06-10-2010
I don't understand, it should be easier, if you post a bigger simple from your input.

Anyway, glad you got the desired output Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep -F for special character

a='CASH$$A' /usr/xpg4/bin/grep -F "$a" *.txt It is not able to grep CASH$$A string as it contains special character $$. I also tried with /usr/xpg4/bin/grep -F '$a' *.txt but still not working. I have to assign CASH$$A to a variable and serach that variable..i dont want to search the... (8 Replies)
Discussion started by: millan
8 Replies

2. Shell Programming and Scripting

Grep with special Characters

Need Help For GREP I have a file say g1.txt and content of file is below REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDrives /t REG_DWORD /d 4 /f , REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoClose /t REG_DWORD /d 1 /f ,... (4 Replies)
Discussion started by: jalpasoni
4 Replies

3. UNIX for Dummies Questions & Answers

grep for special charecters

Hi, I need to grep for text between " 01/Aug" and " 02/Aug" in a text file. The awk command usually fails with the error saying "line too long" Is there other simpler ways to achieve this ? (12 Replies)
Discussion started by: shifahim
12 Replies

4. Programming

Help to grep string in log files

hello guys.., i have some problem with grepping strings in log files.. so..,i need an java logic on how to grep srtings in log files the output must be in gui.., please help me .. regards raghuraipur:confused: (1 Reply)
Discussion started by: raghuraipur
1 Replies

5. Shell Programming and Scripting

grep for a special range

hi, i search a command to get follow solution: file: 21082009mueller01testtest 22082009mueller02testtest 23082009mueller03testtest 24082009mueller02testtest 25082009mueller03testtest Solution: I search all lines with "mueller02" at the range 8 to 17 It is possible with greb... (5 Replies)
Discussion started by: Timmää
5 Replies

6. UNIX for Dummies Questions & Answers

Using GREP for special characters

Hi folks I am issuing the following command: grep "" * Looking for the characters \/:*?"<>|#+%& within all files in a directory, but the command fails being unhappy with pipe: ksh: 0403-057 Syntax error: `|' is not expected. How do I force the command to take the pipe | ? I guess... (2 Replies)
Discussion started by: daveaasmith
2 Replies

7. UNIX for Advanced & Expert Users

grep in special character

All, I am trying to grep "-----" from a test when i use this i am getting the below error. What is the reason for this ?????... How can i over come this ##) echo "----------------- test_sys_job -----------------" | grep "-----------------" grep: illegal option -- - grep: illegal... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies

8. Shell Programming and Scripting

Need to grep for .log files

Hi, Have two files. 1. robin.log 2. robin_log When is grep i shuld get only robin.log file. Please help. I Tried ls | grep ".log" But its not working Thanks Robin (6 Replies)
Discussion started by: robinbannis
6 Replies

9. UNIX Desktop Questions & Answers

grep with special characters

Hi there I need to grep for a detail from a file. The pattern to search for involves escape sequences in it. This causes for the problem. grep "P\_SOME\_STRING\_SEARCH" filename Note, I have line like below in the file and expect it to grep. select * from my_system_param ... (3 Replies)
Discussion started by: guruparan18
3 Replies

10. Shell Programming and Scripting

Grep with Special Characters

I need to sort a file, the sort is not a alphabetical sort, it's based on a predefined order which is read from a file called fSortOrder. The format of the fSortOrder file is : STARTPATH" .... .... The file that needs to be sorted is called tmpUnsorted and contains data in the format : ... (6 Replies)
Discussion started by: Vashj
6 Replies
Login or Register to Ask a Question