FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 12-13-2008, 05:35 PM
Rick Pasotto
 
Default Copy a file one hundred times

On Sat, Dec 13, 2008 at 07:12:32PM +0000, Rodolfo Medina 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?

c=0; while [ $c -lt 100 ]; do c=$[c + 1]; n='000'$c; cp file.jpg file${n: -3}.jpg; done

--
"Never compromise principle, not even on special occasions."
--- Robert Bitzer (quoted by Marcia Pearce;
quoted in Diane Dreher 1996
_The Tao of Personal Leadership_ pg 221)
Rick Pasotto rick@niof.net http://www.niof.net


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 12-13-2008, 05:35 PM
John Hasler
 
Default Copy a file one hundred times

Rodolfo writes:
> 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.

for I in {1..100}; do cp file.jpg file$I.jpg ; done

But what are you actually trying to achieve?
--
John Hasler


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 12-13-2008, 05:35 PM
"Manon Metten"
 
Default Copy a file one hundred times

Hi Rodolfo

On Sat, Dec 13, 2008 at 8:12 PM, Rodolfo Medina
<rodolfo.medina@gmail.com> 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.


#!/bin/bash

for x in `seq 1 100`; do

if [[ x -lt 10 ]]; then cp file.jpg file-00$x.jpg;

elif [[ x -lt 100 ]]; then cp file.jpg file-0$x.jpg;

else cp file.jpg file-$x.jpg;

fi

done


Greetings, Manon.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 12-13-2008, 05:41 PM
Rick Pasotto
 
Default Copy a file one hundred times

On Sat, Dec 13, 2008 at 07:35:44PM +0100, Manon Metten wrote:
> Hi Rodolfo
>
> On Sat, Dec 13, 2008 at 8:12 PM, Rodolfo Medina
> <rodolfo.medina@gmail.com> 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.
>
>
> #!/bin/bash
>
> for x in `seq 1 100`; do
>
> if [[ x -lt 10 ]]; then cp file.jpg file-00$x.jpg;
>
> elif [[ x -lt 100 ]]; then cp file.jpg file-0$x.jpg;
>
> else cp file.jpg file-$x.jpg;
>
> fi
>
> done

I forgot about seq. This is even better (the -w left pads with zero for
equal width):

for x in $(seq -w 1 100); do cp file.jpg file${c}.jpg; done

--
"Faith is often the boast of the man who is too lazy to investigate."
-- F.M. Knowles
Rick Pasotto rick@niof.net http://www.niof.net


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 12-13-2008, 05:50 PM
Osamu Aoki
 
Default Copy a file one hundred times

On Sat, Dec 13, 2008 at 07:12:32PM +0000, Rodolfo Medina 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?

ere is one without looping :-)

$ seq 1 100 | sed "s/^(.*)$/file1.jpg/" |xargs -n1 echo file.jpg


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 12-13-2008, 06:11 PM
"Thomas Preud'homme"
 
Default Copy a file one hundred times

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

--
Why debian : http://www.debian.org/intro/why_debian
 
Old 12-13-2008, 08:13 PM
Tzafrir Cohen
 
Default Copy a file one hundred times

On Sun, Dec 14, 2008 at 03:50:31AM +0900, Osamu Aoki wrote:
> On Sat, Dec 13, 2008 at 07:12:32PM +0000, Rodolfo Medina 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?
>
> ere is one without looping :-)
>
> $ seq 1 100 | sed "s/^(.*)$/file1.jpg/" |xargs -n1 echo file.jpg

err.. does this work?

--
Tzafrir Cohen | tzafrir@jabber.org | VIM is
http://tzafrir.org.il | | a Mutt's
tzafrir@cohens.org.il | | best
ICQ# 16849754 | | friend


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 12-13-2008, 09:57 PM
Alex Samad
 
Default Copy a file one hundred times

On Sat, Dec 13, 2008 at 09:13:07PM +0000, Tzafrir Cohen wrote:
> On Sun, Dec 14, 2008 at 03:50:31AM +0900, Osamu Aoki wrote:
> > On Sat, Dec 13, 2008 at 07:12:32PM +0000, Rodolfo Medina 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?
> >
> > ere is one without looping :-)
> >
> > $ seq 1 100 | sed "s/^(.*)$/file1.jpg/" |xargs -n1 echo file.jpg
>
> err.. does this work?

I think he put an echo to show the lines

echo file.jpg file1.jpg

....

>
> --
> Tzafrir Cohen | tzafrir@jabber.org | VIM is
> http://tzafrir.org.il | | a Mutt's
> tzafrir@cohens.org.il | | best
> ICQ# 16849754 | | friend
>
>
> --
> To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
>
>

--
"President Musharraf, he's still tight with us on the war against terror, and that's what I appreciate. He's a -- he understands that we've got to keep Al Qaeda on the run, and that by keeping him on the run, it's more likely we will bring him to justice."

- George W. Bush
08/22/2002
Ruch, OR
 
Old 12-14-2008, 12:32 AM
"Manon Metten"
 
Default Copy a file one hundred times

Hi Rick,

On Sat, Dec 13, 2008 at 7:41 PM, Rick Pasotto <rick@niof.net> wrote:

> I forgot about seq. This is even better (the -w left pads with zero for
> equal width):
>
> for x in $(seq -w 1 100); do cp file.jpg file${c}.jpg; done


Waw! Great one-liner.

BTW: Guess you meant file${x}.jpg;

Greetings, Manon.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 12-14-2008, 01:16 AM
Osamu Aoki
 
Default Copy a file one hundred times

On Sat, Dec 13, 2008 at 09:13:07PM +0000, Tzafrir Cohen wrote:
> On Sun, Dec 14, 2008 at 03:50:31AM +0900, Osamu Aoki wrote:
> > On Sat, Dec 13, 2008 at 07:12:32PM +0000, Rodolfo Medina 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?
> >
> > ere is one without looping :-)
> >
> > $ seq 1 100 | sed "s/^(.*)$/file1.jpg/" |xargs -n1 echo file.jpg
>
> err.. does this work?

THIS DOES NOT WORK! Agh...

This was my local test script :-) s/echo/cp/ is needed as you may have
guessed.

$ seq 1 100 | sed "s/^(.*)$/file1.jpg/" |xargs -n1 cp file.jpg

This is one should do
cp file.jpg file1.jpg
cp file.jpg file2.jpg
...
cp file.jpg file100.jpg

Osamu


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

Thread Tools




All times are GMT. The time now is 06:51 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org