Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locating a file

Status
Not open for further replies.

dahamcharith

Technical User
Jul 11, 2007
5
LK
Hi All AIX Gurus,

I am trying to locate a specific file within large set of folders. I have been using the follwoing command,

find . -name 124156.xml -type f -exec grep credit /dev/null {} \;

I cant seem to get the folder and the file which this generes the result. Can some one analyze this for me and tell me what I am doing wrong.

Thank you for your support,
DC
 
Your command is trying to do two things
Code:
find . -name 124156.xml -type f -exec grep credit /dev/null {} \;
is finding the file and then running grep.

If you want to find all files which are called 124156.xml and have the word 'credit' in them then the simple answer is
Code:
for file in $(find . -name 124156.xml -type f )
do
  grep -q credit $file && echo $file
done
If you want to get fancy you might try something like
Code:
find . -name 124156.xml -type f -exec grep -q credit {} && echo {} \;
Or, if all you want are the lines which have the word credit in them from the file 124156.xml then
Code:
find . -name 124156.xml -type f -exec grep credit {} \;

Ceci n'est pas une signature
Columb Healy
 
As I understand it, on my AIX 5.1 machine, the -E flag is meaningless in this context - please correct me if I'm wrong. The man page shows
man grep said:
-E Treats each pattern specified as an extended regular expression (ERE). A NULL
value for the ERE matches every line.

Note: The grep command with the -E flag is the same as the egrep command,
except that error and usage messages are different and the -s flag functions
differently.
So, I would expect
Code:
find . -name 124156.xml|grep -E credit
to return a list of files called 124156.xml and pass that list through 'grep -E credit' which would return nothing.

Ceci n'est pas une signature
Columb Healy
 
Thank you all for the information...

I used find . -name 124156.xml -type f -exec grep -q credit {} && echo {} \;


thanks to all!!!!

:D
 
For future reference, you could just use "grep -l credit {}" (that's a lowercase L) where
you used "grep -q credit {} && echo {}", to the same effect.

- Rod


IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

A Simple Code for Posting on the Web
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top