Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie help : rename multiple files based on text array

Status
Not open for further replies.

Odium

MIS
Mar 10, 2006
22
ES
hello people,

i neep some help,

i have a bunch of files, let's say :

1-33456.jpg
1-22341.jpg
1-36771.jpg
1-abcde.jpg

on the other hand i have a text file with 2 columns asa follows:

36771 yellow
33456 red
abcde black
22341 pink

what i need :

i need to rename each file with color correspondance from text file.

so file named 1-33456.jpg becomes red.jpg


i've already tryed working with text arrays but no success...
any help will be much apreciated.
thx for your time.
 
Try this (presumes that the *.jpg files are in the current directory, and that the colours are stored in a file called colours):

Code:
ls *.jpg | awk '
        BEGIN {
                while (getline < "colours") { colour[$1]=$2 }
                close("colours")
                FS="[-.]"
        }
        {
                newname=$0
                sub("1-"$2,colour[$2],newname)
                print "mv",$0,newname
        }
' | sh -x

Annihilannic.
 
thanks a lot for help !

but i forgot mention an important detail :)

i'm using awk for windows ....so i cannot use the mv command
nor use sh ...

any thoughs ?
 
Hi

Then
[ol]
[li]put the script into a file and pass its name to [tt]awk95[/tt][/li]
[li]replace [tt]mv[/tt] with [tt]ren[/tt][/li]
[li]redirect the script's output into a file with .bat extension[/li]
[li]run the .bat file[/li]
[/ol]
Or
[ol]
[li]Install CygWin.[/li]
[/ol]


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top