The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find , grep james94538 UNIX for Dummies Questions & Answers 3 2 Days Ago 06:03 PM
grep, find or awk? netrom UNIX for Dummies Questions & Answers 4 04-09-2008 02:03 PM
grep and find MEllis5 UNIX for Dummies Questions & Answers 1 04-07-2008 05:16 AM
find and grep sarwan High Level Programming 4 04-10-2006 04:05 AM
find & grep Anika UNIX for Dummies Questions & Answers 11 02-01-2001 08:19 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-07-2008
Registered User
 

Join Date: Jan 2008
Posts: 16
Stumble this Post!
find then grep

I have some patterns that I need to match with the content of several files and I'm having trouble to do it

Here is what I tried already :

ksh won't even execute this
Code:
#!/bin/ksh
path="/export/home/ipomwbas"
pattern=$path"/flags"
find . -name "*.properties" |\
while read file; do
  /usr/xpg4/bin/grep -f $pattern $file | cat >> results
done
and this doesn't give me the expected output:

Code:
find . -name "*.properties" | xargs /usr/xpg4/bin/grep -f flags | cat >> results
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-07-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 541
Stumble this Post!
Why not simply use grep instead of the xpg4 version and there is no need for that cat process either...

find . -name "*.properties" | xargs grep -f flags >> results
Reply With Quote
  #3 (permalink)  
Old 03-07-2008
Registered User
 

Join Date: Jan 2008
Posts: 16
Stumble this Post!
I tried without the xpg4 version of grep, but it gives : grep: illegal option -- f
Reply With Quote
  #4 (permalink)  
Old 03-10-2008
Registered User
 

Join Date: Jun 2007
Posts: 377
Stumble this Post!
Code:
find . -name "*.txt" | xargs grep pattern | sed 's/^.*\.txt://' | cat  >> c
Reply With Quote
  #5 (permalink)  
Old 03-11-2008
Registered User
 

Join Date: Jan 2008
Posts: 16
Stumble this Post!
@summer_cherry

I modified your suggestion to fit my situation like this :
Code:
find . -name "*.properties" | xargs /usr/xpg4/bin/grep -f flags | sed 's/^.*\.properties://' | cat  >> c
but it gave me weird results. There was a lot of entries in the file, but none of them contained patterns from my flags file, like :

Code:
PROPERTIES_PATH         = c:/java/SM_Web/config/
I don't know if this can help you, but this is the content of my flags file

Code:
.*\.host\=
.*\.port\=
.*\.url\=
.*\.schema\=
.*\.user.*
.*\.password\=
.*\.simulator.flag.*
Reply With Quote
  #6 (permalink)  
Old 03-11-2008
Registered User
 

Join Date: Jun 2006
Posts: 159
Stumble this Post!
This is working for me on Ubuntu (with regular expression syntax in my pattern file).

Code:
find . -iname '*.ext' | xargs egrep -f patterns.txt
Reply With Quote
  #7 (permalink)  
Old 03-13-2008
Registered User
 

Join Date: Jan 2008
Posts: 16
Stumble this Post!
The find didn't work because of the -iname argument
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux, ubuntu

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0