The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 10-09-2008 09:03 PM
grep, find or awk? netrom UNIX for Dummies Questions & Answers 4 04-09-2008 05:03 PM
grep and find MEllis5 UNIX for Dummies Questions & Answers 1 04-07-2008 08:16 AM
find and grep sarwan High Level Programming 4 04-10-2006 07:05 AM
find & grep Anika UNIX for Dummies Questions & Answers 11 02-01-2001 12:19 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-07-2008
flame_eagle flame_eagle is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 16
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
  #2 (permalink)  
Old 03-07-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
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
  #3 (permalink)  
Old 03-07-2008
flame_eagle flame_eagle is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 16
I tried without the xpg4 version of grep, but it gives : grep: illegal option -- f
  #4 (permalink)  
Old 03-10-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
Code:
find . -name "*.txt" | xargs grep pattern | sed 's/^.*\.txt://' | cat  >> c
  #5 (permalink)  
Old 03-11-2008
flame_eagle flame_eagle is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 16
@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.*
  #6 (permalink)  
Old 03-11-2008
ShawnMilo ShawnMilo is offline
Registered User
  
 

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

Code:
find . -iname '*.ext' | xargs egrep -f patterns.txt
Closed Thread

Bookmarks

Tags
linux, ubuntu

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0