>
> 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${x}.jpg; done
>
correction----^
Nice! Something I have been looking for quite some time. I was using the
elseif statements before I saw this.
Thanks a ton.
--
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@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
12-14-2008, 04:19 AM
"H.S."
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@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
12-14-2008, 04:24 AM
"H.S."
Copy a file one hundred times
Thomas Preud'homme wrote:
> 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
Just for reference, this pattern matching and chopping is explained more
with examples here:
http://www.ibm.com/developerworks/library/l-bash.html#N1010B
--
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@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
12-21-2008, 08:58 PM
Jörg-Volker Peetz
Copy a file one hundred times
Osamu Aoki wrote:
> 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 :-)
<snip>
> $ seq 1 100 | sed "s/^(.*)$/file1.jpg/" |xargs -n1 cp file.jpg
>
I like my women like I like my coffee - purchased at above-market
rates from eco-friendly organic farming cooperatives in Latin America.
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
12-21-2008, 10:12 PM
Tzafrir Cohen
Copy a file one hundred times
On Sun, Dec 21, 2008 at 04:45:21PM -0600, Ron Johnson wrote:
> On 12/21/08 15:58, Jörg-Volker Peetz wrote:
>> $ seq -w 1 1 10 | xargs -i -n1 cp file.jpg file{}.jpg
>
> What's with the {}? An implied variable?
$ LANG=C man xargs | grep -C 2 '{}'
-i[replace-str]
This option is a synonym for -Ireplace-str if replace-str is
specified, and for -I{} otherwise. This option is deprecated;
use -I instead.
Here, the first invocation of xargs has no input line length limit be-
--
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
12-22-2008, 02:33 AM
"Slim Joe"
Copy a file one hundred times
2008/12/14, Rodolfo Medina <rodolfo.medina@gmail.com>:
> 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?
You could try something like:
cat file.pdf | tee `seq -w 0 100 | sed 's+.*+file_&.pdf+'` > /dev/null
(1) The "cat" command pipes the contents of the file "file.pdf"
to the command "tee" which can dump the contents of the file
to both a file (or files) and to stdout.
(2) The `seq -w [...]` creates the file names.
(3) The "> /dev/null" is necessary unless you want the contents of
the file to pollute your screen.
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
12-22-2008, 01:41 PM
Jörg-Volker Peetz
Copy a file one hundred times
Tzafrir Cohen wrote:
> On Sun, Dec 21, 2008 at 04:45:21PM -0600, Ron Johnson wrote:
>> On 12/21/08 15:58, Jörg-Volker Peetz wrote:
>>> $ seq -w 1 1 10 | xargs -i -n1 cp file.jpg file{}.jpg
>> What's with the {}? An implied variable?
>
> $ LANG=C man xargs | grep -C 2 '{}'
> -i[replace-str]
> This option is a synonym for -Ireplace-str if replace-str is
> specified, and for -I{} otherwise. This option is deprecated;
> use -I instead.
>
yes, {} was the default placeholder in the xargs command. According to the
man-page it should now be