[Techtalk] bash/perl script to rename files...

Erin Mulder meara99 at yahoo.com
Fri Oct 26 15:31:36 EST 2001


[Overkill for just one file, but... ]

I love to keep this "mangle" script around that can search and
replace recursively through particular files under some root.
(e.g. to update version numbers, package names, etc.)

#! /bin/sh
#
# Usage: mangle text1 text2
#        Replace all occurrences of 'text1' with 'text2' in every file
#        given on standard input.  For example, to replace all
#        occurrences of 'foo' with 'bar' in files whose names end in
#        .txt, issue the following command:
#
#        find . -type f -name \*.txt -print | mangle foo bar

while read i; do
    sed "s|$1|$2|g" $i > $i.tmp && mv -f $i.tmp $i
done


----- Original Message ----- 
From: "Walt" <pippin at fred.net>
To: <techtalk at linuxchix.simegen.com>
Sent: Friday, October 26, 2001 2:07 PM
Subject: [Techtalk] bash/perl script to rename files...


> I need a perl script that replaces spaces
> in a filename with underscores...
> 
> I'm sure that this can be achieved, I just
> don't know how to do it.
> 
> Thanks!
> Walt
> 
> -~
> 
>      In the animal kingdom, the rule is eat or be eaten; in the
> 
>      human kingdom, define or be defined.
>                          Thomas Szasz
> 
> 
> _______________________________________________
> Techtalk mailing list
> Techtalk at linuxchix.org
> http://www.linuxchix.org/mailman/listinfo/techtalk


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com





More information about the Techtalk mailing list