Re: find | xargs | grep over filenames with spaces
- From: André Gillibert <MetaEntropy.removeThis@xxxxxxxxx>
- Date: Thu, 1 Jan 2009 01:38:06 +0100
salmobytes <salmobytes@xxxxxxxxxxxx> écrivit:
Let's say I have a directory tree where both filenames and directory
names contain spaces in the names (not a good idea but it
happens I want to deal with it).
I know how to write a recursive script to fix the filenames.
But let's say I choose not to change the names, and I want to grep
for a pattern in all files with suffix *.txt
for file in `find . -name "*\.txt"`
do
grep "whatever" "$file"
done
....throws all sorts of errors, because grep tries
look at files that don't exist (parses space delimited
bits and pieces of file and directory names).
find . -name '*.txt' -print0 | xargs -0 grep -h "whatever"
Or:
find . -name '*.txt' -exec grep whatever {} \;
The latter supports an unlimited number of file names.
These commands may contain GNU-isms. I'm sorry for inconvenience.
--
André Gillibert
.
- Follow-Ups:
- Re: find | xargs | grep over filenames with spaces
- From: Steffen Schuler
- Re: find | xargs | grep over filenames with spaces
- References:
- find | xargs | grep over filenames with spaces
- From: salmobytes
- find | xargs | grep over filenames with spaces
- Prev by Date: find | xargs | grep over filenames with spaces
- Next by Date: Re: find | xargs | grep over filenames with spaces
- Previous by thread: find | xargs | grep over filenames with spaces
- Next by thread: Re: find | xargs | grep over filenames with spaces
- Index(es):
Relevant Pages
|