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

Re: Multiple files



On Fri, May 31, 2002 at 10:54:16AM -0400, Daniel D Jones wrote:
> How does one handle multiple files via most command line utilities?  For
> example, suppose you have a handful of perl scripts (*.pl) and you want
> to save them in the same directory with a different extension.  The
> command
> 
> cp *.pl *.bak

comp.unix.shell FAQ, I think.

for f in *.pl; do cp $f `basename $f`.bak; done

> Or suppose you have a series of perl scripts which are saved in DOS
> line-end format.  The extra ^M on the bang line causes bash not to
> recognize the path to perl, and the script to fail.  Sounds like a job
> for sed.
> 
> sed s/^M// *.pl > *.unix

again, for f in *.pl; do sed -e s/^M// $f > `basename $f`.bak; done

but in this case you can tell perl to work on all the files at once, which
is neater:

perl -i~ -pe 's/\r//' *.pl

which will update the *.pl files, leaving backups in *.pl~

> Again, the file naming criteria doesn't work.  I could write a script
> which essentially generates a new command for each file fitting the

technically, that's what the above do, but it's not really very complicated
once you're used to the shell.

(the key to using *.foo on command lines is to remember that the shell
expands it before handing the list to the program.)

SRH
-- 
Steve Haslam      http://www.arise.demon.co.uk/         araqnid@innocent.com
Debian GNU/Linux Maintainer                               araqnid@debian.org
but I won't admit to needing you
I'll never say that's true, not to you                  [sister machine gun]

Attachment: pgp68_L1LEheo.pgp
Description: PGP signature


Reply to: