Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Dear all,
I'm trying to rename a bunch of photos according to their subjects' names.
I have several thousand photos of people, each named along the following lines
423big234.jpg
where the 423 is the key to the person's name. I have a list of the correspondence between numbers and names and wish to rename accordingly.
Here's what I have so far:
#!/bin/bash for a in $(ls); do i=$(awk '{print $1}' $a) j=$(awk '{print $2$3$4}' $a) for k in $(ls ../femalemodels); do target=$(echo $k | sed 's/^$i/$j/g') mv "../femalemodels/$k" "../femalemodels/$target" done doneAll help hugely appreciated.

Sorry, further explanation needed.
I split the list of numbers and names in to separate files, hence the for i in $(ls).
The problem is that the sed isn't working. It keeps telling me the files are the same.

try to use double quotes. if that fails, describe clearly again what your files are like, and what you want them to be renamed to. show any input files if there are any

Tried the double quotes too!
The files are all jpegs, all named (number)big(number).jpg, and I want to change them from
(number)big(number).jpg
to
(name)big(number).jpg
where (number) is the first field in a text file and (name) is the concatenation of the next three fields.
Here's what I'm trying now:
mv ../femalemodels/$i*.jpg ../femalemodels/new/$j*/but the wildcard isn't working here either.
I feel so stooopid.

how does the files in femalemodels directory look like? you mentioned names, what kind of names? give as much info as possible.

Here's how I did it. The tricky part was escaping the variables with the sed script.
listoffiles=~/Desktop/test/target/lists/ files=~/Desktop/test/target/images/ new=~/Desktop/test/target/new/ for a in $(ls $listoffiles); do i=$(awk '{print $1}' $listoffiles$a) j=$(awk '{print $2$3$4}' $listoffiles$a) printf "$i $j\n" for k in $(ls $files); do echo $k | sed s/^"$i"/"$j"/g >> out.txt cp $files$k $new$(echo $k | sed s/^"$i"/"$j"/g); done doneI had been trying sed 's/^"$i"/"$j"/g' and variations thereon. Silly me.
Anyway it's almost a useful tool now, I'll generalise it so if anyone's interested I'll email it to them.

do away with the ls in the for loop. its useless. just use shell expansion
for a in $listoffiles
also, try to give your variables meaningful names.

![]() |
Problem while executing s...
|
Ok PLEASE Help!!
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |