Re: Copy a file one hundred times



Thomas Preud'homme wrote:
The Saturday 13 December 2008 20:12:32 Rodolfo Medina, you wrote :
I need the right syntax to copy file.jpg 100 times with one command so to
get 100 files named file1.jpg, file2.jpg, ..., file100.jpg.

Can anybody suggest how to achieve that?

Thanks for any reply
Rodolfo


filevar="file.jpg"
basefile=${filevar%.[^.]*}
extension=${filevar##^.*.}
for i in `seq 100`
do
cp $filevar $basefile$i.$extension
done

with file the file to copy, basefile the file without the last extension and
extension the last extension (without the dot).

In a function it would be

function hundred-copy ()
{
filevar=$1 # The file to copy a hundred time
basefile=${filevar%.[^.]*} # We delete all the end from the last dot (eg
a dot followed by any others caracters)
extension=${filevar##^.*.} # We delete all the beginning until the last
dot included (biggest prefix with any caracters followed by a dot)
do
cp $filevar $basefile$i.$extension # file become
filenumber.extension
done
}

Regards,

Thomas Preud'homme



Nice job of pattern matching and extraction without using sed! Gives me
a new tool to create new filesname based on input files. Usually I run
an experiment which takes filenames as input and produces multiple files
for each file to save results in.

Thanks.

--

Please reply to this list only. I read this list on its corresponding
newsgroup on gmane.org. Replies sent to my email address are just
filtered to a folder in my mailbox and get periodically deleted without
ever having been read.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx
with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: RESULT - UK Usenet Committee Elections 2005
    ... On the basis of First Preferences alone, Paul didn't come last, Thomas ... Thomas elected following transfer of Graham's surplus ... bsalter at ukvoting dot org dot uk ...
    (uk.net.news.management)
  • Re: Search & Replace with RegEx
    ... I'm using a version of MOOX Firefox ... except when I install or uninstall an ... > extension, in which case I then have to physically edit the compreg.dat ... Thomas Güttler, http://www.thomas-guettler.de/ ...
    (comp.lang.python)
  • Re: OT Mac help please!
    ... Keith Freeman wrote: ... He doesn't know how to change the extension. ... Apparently a Mac doesn't have a right-click function for Properties. ... e-mail only to keith DOT freeman AT wanadoo DOT nl ...
    (rec.music.makers.guitar.jazz)
  • Re: Ada.Directories.Base_Name and dot files
    ... dot files very gracefully. ... Instead of returning a null string when the first character is a dot, ... "extension" name, Unix is a lot ...
    (comp.lang.ada)
  • Re: how to get the file extension from a pathname
    ... want to extract the extension of a file as a String.Suppose the ... represents one of the predefined character classes (any ... (full-stop, period, dot, decimal, etc.) ... single backslash would be seen as an illegal escape character: ...
    (comp.lang.java.programmer)