bulk rename pod1 > pod2 needed

Joe joe at nationnet.com
Tue Feb 17 05:39:17 MST 2009


I think the following script will for for your pattern.

------ CUT HERE -------
#!/bin/bash

# To rename ccna.pod1.pc1.ext is renamed to ccna.pod2.pc1.ext

for file in $(ls ccna*ext | sort -rn -k 1.9)
do
        let ix=$(echo $file | sed -e 's/.*pod//' -e 's/.pc..ext//')
        let iy=$ix+1
        newfile=$(echo $file | sed "s/pod$ix/pod$iy/")
        if [ -e $newfile ] ; then
                # Shouldn't get here
                echo "Rename error of $newfile"
                continue
        fi
        mv $file $newfile
done
---- CUT HERE ----

James Mcphee wrote:
> assuming you're just trimming off ccna, pc1, and ext
>
> for i in $( ls )
> do
> mv $i $( echo $i | awk -F. '{ print $3 }' )
> done
>
> That would move them to pod# names.
>
> On Mon, Feb 16, 2009 at 5:33 PM, Dennis Kibbe 
> <dennisk at sdf.lonestar.org <mailto:dennisk at sdf.lonestar.org>> wrote:
>
>     Can someone suggest a way to rename a directory of files like this:
>
>     ccna.pod1.pc1.ext is renamed to ccna.pod2.pc1.ext
>     ccna.pod2.pc1.ext is renamed to ccna.pod3.pc1.ext
>
>     and so on.
>
>     (Aside: Hans, if I were able to take your scripting class I won't
>     be asking this now. :-)
>
>     Dennisk
>
>     --
>     "Free as in Freedom"
>     Free Software Foundation
>     ---------------------------------------------------
>     PLUG-discuss mailing list - PLUG-discuss at lists.plug.phoenix.az.us
>     <mailto:PLUG-discuss at lists.plug.phoenix.az.us>
>     To subscribe, unsubscribe, or to change your mail settings:
>     http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>
>
>
>
> -- 
> James McPhee
> jmcphe at gmail.com <mailto:jmcphe at gmail.com>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss at lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


More information about the PLUG-discuss mailing list