[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: automated editing of text files



Aéris wrote:
> Le 16/09/2011 23:40, Bob Proulx a écrit :
> > If there are no *.txt files then the file glob won't be expanded,
> > nothing to expand it to, and then your shell script will get a literal
> > "*.txt" as an argument.  If that minor point is important to you then
> > check that the file exists and simply break or continue if it does not.
> > 
> >   for i in *.txt; do
> >     test -f "$i" || continue
> >     ./add-pre-nl.sh "$i"
> >   done
> 
> Simplest version :
> 	find -type f -name "*.txt" -exec add-pre-nl.sh {} \;

Ah...  Very good!  An excellent suggestion!  'find' rocks!  I will
note three things here however.

* One is that the find will recurse down through a possibly deep
hierarchy of directories.  It isn't an identical alternative for just
looking for *.txt in the current directory.  But probably that
difference isn't important here.  Or perhaps that difference will be a
really desirable feature.

* Secondly if the add-pre-nl.sh script handle multiple file arguments
then instead of \; use + so that it calls it fewer times with as many
file arguments as possible.  It will be more efficient that way.

* And lastly that you forgot to include the directory path to find,
probably a '.' wanted here.

  find . -type f -name "*.txt" -exec add-pre-nl.sh {} +

:-)

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: