Here's one for you scripting gurus; I have a directory with a bunch of tarballs in it (GTK+ themes, actually). Each of the names is like this: theme-name[1].tar.gz I want the names to be like this: theme-name.tar.gz Can't I write a script that will automatically rename all of the files? I have around 300 of them so far, and I'd really rather not do it by hand :). PS: Yes, I changed my email address again. All the more reason to post your RE:'s to the list ;). -- -=|JP|=- (Resident GNUbie) Jon Pennington | SuSE Linux 6.2 super-suser@excite.com | Kernel 2.2.10 Kansas City, Missouri | AMD K6-III 450 ________________________________________________________________ Get FREE voicemail, fax and email at http://voicemail.excite.com Talk online at http://voicechat.excite.com -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
Hi Jon,
what about ...?
a) s1:~/kk #mkdir kk
b) s1:~/kk #cd kk //playground :-)
c) s1:~/kk #for j in 1 2 3 4 5;do cat > theme-name[$j].tar.gz;done //with
5 ctrl-D I have some test files
d) s1:~/kk # for j in 1 2 3 4 5;do mv theme-name[$j].tar.gz
theme-name$j.tar.gz;done //like this you rename every
"theme-name[1].tar.gz" file to "theme-name1.tar.gz", for instance (j
equals 1 for the 1st iteration, 2 for the second ...). You can
modify the procedure to meet your needs as you wish...
ps: I am playing with "bash"
pss: if this is not powerful enough for you,
you can always go meet Mr.awk ... I think that O'Reilly (typical!) has a
very good book about it. You will tell us...
I hope that this may be useful to you.
bye!
jl
On Fri, 1 Oct 1999, Jon Pennington wrote:
uper- > Here's one for you scripting gurus;
super- >
super- > I have a directory with a bunch of tarballs in it (GTK+ themes, actually).
super- > Each of the names is like this:
super- >
super- > theme-name[1].tar.gz
super- >
super- > I want the names to be like this:
super- >
super- > theme-name.tar.gz
super- >
super- > Can't I write a script that will automatically rename all of the files? I
super- > have around 300 of them so far, and I'd really rather not do it by hand :).
super- >
super- > PS: Yes, I changed my email address again. All the more reason to post your
super- > RE:'s to the list ;).
super- >
super- > --
super- > -=|JP|=- (Resident GNUbie)
super- > Jon Pennington | SuSE Linux 6.2
super- > super-suser@excite.com | Kernel 2.2.10
super- > Kansas City, Missouri | AMD K6-III 450
super- >
super- >
super- >
super- >
super- > ________________________________________________________________
super- > Get FREE voicemail, fax and email at http://voicemail.excite.com
super- > Talk online at http://voicechat.excite.com
super- >
super- > --
super- > To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com
super- > For additional commands send e-mail to suse-linux-e-help@suse.com
super- > Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
super- >
super- >
========== ____<E-MAILS>_____________________________
Jose Luis Garcia Pacheco | jlgp@jlgarciapacheco.virtualave.net |
| jgarciay@supelec-rennes.fr |
\|||||||/ |___<WEBS>_______________________________|
< o o > | http://jlgarciapacheco.virtualave.net |
\ o / |----------------------------------------|
---oOOo-------oOOo--- | 6, Av. de Belle Fontaine.Logement C-209|
*ETSI. Telecom. Univ | 35510 Cesson-Sevigne. France. |
Politecnica UPM. SPAIN |___
On 01-Oct-99 Jose Luis.Garcia Pacheco wrote:
Hi Jon,
pss: if this is not powerful enough for you, you can always go meet Mr.awk ... I think that O'Reilly (typical!) has a very good book about it. You will tell us...
Jose is right -- for this sort of thing 'awk' is the name of the game!
Not only is the O'Reilly book good -- you should also try to get hold
of the original
Aho
Weinberger
Kernighan
book called "The AWK Programming Language" (Addison-Wesley 1988)
which is not large (204 pp) and, once you have got used to its
ultra-compact style, is a very good reference (though it does
not cover GNU awk [aka gawk] extensions).
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding)
Hello Jon, On Fri, Oct 01, 1999 at 12:10:18AM -0700, Jon Pennington wrote:
theme-name[1].tar.gz I want the names to be like this: theme-name.tar.gz
Can't I write a script that will automatically rename all of the files? I have around 300 of them so far, and I'd really rather not do it by hand :).
Easy, use Perl. Save this script as 'guru.pl' in your themes-dir <grin>. Do a 'chmod +x guru.pl'. Use it as: './guru.pl *'. Good luck, Cees. --------------------------------------------------------------------- #!/usr/bin/perl -w use strict; foreach my $file (@ARGV) { if ($file =~ /(.+)\[.+\]\.tar\.gz/) { rename("$file", "$1.tar.gz") or die("Can not rename $file to $1.tar.gz: $!\n"); print("Renamed: $file to $1.tar.gz\n"); } else { print("Not recognized: $file\n"); } } --------------------------------------------------------------------- -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
On ven, 01 ott 1999, Jon Pennington wrote:
Here's one for you scripting gurus;
I have a directory with a bunch of tarballs in it (GTK+ themes, actually). Each of the names is like this:
theme-name[1].tar.gz
I want the names to be like this:
theme-name.tar.gz
Can't I write a script that will automatically rename all of the files? I have around 300 of them so far, and I'd really rather not do it by hand :).
This simple script should work for you: #!/bin/sh for i in `ls *.tar.gz`; do echo "Renaming $i" mv $i `echo $i | sed "s/\[.*\]//"` done Give it a name, chmod +x and then execute it. Ciao Maurizio -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
On Fri, Oct 01, 1999 at 03:33:58PM +0200, Maurizio Firmani wrote:
On ven, 01 ott 1999, Jon Pennington wrote:
Here's one for you scripting gurus;
I have a directory with a bunch of tarballs in it (GTK+ themes, actually). Each of the names is like this:
theme-name[1].tar.gz
I want the names to be like this:
theme-name.tar.gz
Can't I write a script that will automatically rename all of the files? I have around 300 of them so far, and I'd really rather not do it by hand :).
This simple script should work for you:
#!/bin/sh
for i in `ls *.tar.gz`; do echo "Renaming $i" mv $i `echo $i | sed "s/\[.*\]//"` done
Give it a name, chmod +x and then execute it.
This will take all *[%].tar.gz files and completely strip the brackets AND numbers from the file name. So, if you have go-theme[1].tar.gz and go-theme[2].tar.gz you're gonna delete some files you don't want to. Maybe it should be: #!/bin/sh for i in `ls *.tar.gz`; do echo "Renaming $i" mv $i `echo $i | sed -e 's/\[//' -e 's/\]//'` done instead? -- Brad Shelton On Line Exchange http://online-isp.com -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
participants (6)
-
bshelton@online-isp.com
-
cees-list@griend.xs4all.nl
-
jgarciay@supelec-rennes.fr
-
maurizio@adriatico.prisma.rm.cnr.it
-
super-suser@excite.com
-
Ted.Harding@nessie.mcc.ac.uk