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

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.


Reply to: