![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| xargs -P | otheus | UNIX for Advanced & Expert Users | 4 | 02-06-2009 04:14 PM |
| search ")" with egrep - egrep: syntax error | sagarjani | UNIX for Dummies Questions & Answers | 7 | 10-14-2008 08:30 AM |
| Egrep cheat sheet anywhere? Looking for meaning of egrep -c | leelm | UNIX for Dummies Questions & Answers | 2 | 01-11-2008 03:37 PM |
| Help with xargs | JimJim | UNIX for Dummies Questions & Answers | 4 | 02-08-2005 07:08 PM |
| xargs | jpprial | UNIX for Dummies Questions & Answers | 4 | 09-17-2001 09:29 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Below is a sample script Code:
jb>cat search
#!/bin/bash
set -x
PATTERN='"'`awk -F: '{printf $2 "|"} END {printf "\b"}' RULE`'"'
echo 'Pattern ['$PATTERN']'
ls -tr *$1* |xargs egrep "$PATTERN"
Sample RULE file Code:
jb>cat RULE P1 :pone P2 :ptwo Sample Output Code:
jb>./search f
++ awk -F: '{printf $2 "|"} END {printf "\b"}' RULE
+ PATTERN='"pone|ptwo"'
+ echo 'Pattern ["pone|ptwo"]'
Pattern ["pone|ptwo"]
+ ls -tr f1 f1.txt f2 f3 f4
+ xargs egrep '"pone|ptwo"'
f2:ptwo
jb>
Directly searching Code:
jb>ls -tr *f* |xargs egrep "pone|ptwo" f1:000pone000 f2:ptwo Sample file content Code:
jb>cat f1 11 000pone000 1111 jb>cat f2 222 ptwo 22222222 jb> Why 'search' doesn't list f1? |
|
||||
|
Thanks,it works.
I have one more question. I have some 20 patterns OR'ed 'pat1|pat2|.....pat20' Each pattern of length around 20 chars and i search around 30 files each of size 10 MB. It takes 2 mins to complete ! Is there any optimal/fast way to do this ? ![]() |
|
||||
|
1.Actually the RULE file names pattern,(RULE file as such is not a pattern) example Code:
>cat RULE SUCCESS :Message sent successfully to FAILURE :Message send failed for Acknowledged :Got ack from #Goes on 2.This line extract the second column ,forms a (ORed) pattern Code:
PATTERN=`awk -F: '{printf $2 "|"} END {printf "\b"}' RULE`
#PATTERN will be 'Message sent successfully to|Message send failed for|Got ack from'
3.Search for all pattern in all file and redirect the o/p to tmp.txt (Takes 2 mins ) Code:
ls -tr *$1* |xargs egrep "$PATTERN" > tmp.txt 4.from tmp.txt do some more filtering,collect statistics (count each pattern) (Dont have problem with this step ,takes very less time.) Code:
Sample Output : SUCCESS :1423 FAILURE : 432 Acknowledged : 764 But step 3 alone takes much of the time(around 2 mins) |
|
||||
|
Once again thanks,It works Search completed in less than 30 secs. My grep version doesn't support -f ,fgrep does. Code:
awk -F: '{print $2}' RULE > tmp.txt
fgrep -f tmp.txt $(ls -tr *26_06_2009*) > tmp2.txt
(Sorry I thought you didn't get my question,but actually I misunderstood your solution ) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|