![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Rename a file name | Aswarth | Shell Programming and Scripting | 0 | 06-04-2008 11:18 AM |
| rename file to file.ext.datetime | tripsat | Shell Programming and Scripting | 2 | 09-20-2007 01:12 PM |
| Not able to rename file | MANISH KU | Shell Programming and Scripting | 2 | 06-27-2007 01:07 AM |
| File rename | redlotus72 | UNIX for Dummies Questions & Answers | 1 | 03-09-2006 08:52 AM |
| Rename part of multiple files | sajjad02 | Shell Programming and Scripting | 4 | 02-22-2005 10:30 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi there,
I hope someone can help me with this problem : I have a directory (/var/www/file/imgprofil) which contains about 10000 JPG files. They have a naming convention thus : prefix-date-key-suffix.jpg they all have the prefix p-20050608- then AAAA is a 4 letter code the suffix is either -g / -v / -m or no suffix the file extension is always .jpg sample : p-20050608-AFWC-g.jpg p-20050608-AFWC-m.jpg p-20050608-AFWC-v.jpg p-20050608-AFWC.jpg p-20050608-AFWD-g.jpg p-20050608-AFWD-m.jpg p-20050608-AFWD-v.jpg p-20050608-AFWD.jpg My problem is that some of the files have 1 or more lower case letters in the 4 letter code, so they are like this : p-20050608-Ajyd-g.jpg p-20050608-Ajyd-m.jpg p-20050608-Ajyd-v.jpg p-20050608-Ajyd.jpg p-20050608-Ajyw-g.jpg p-20050608-Ajyw-m.jpg p-20050608-Ajyw-v.jpg p-20050608-Ajyw.jpg Now, Unix being the case sensitive angel that it is p-20050608-AJYD-g.jpg p-20050608-AJYD-m.jpg p-20050608-AJYD-v.jpg p-20050608-AJYD.jpg p-20050608-AJYW-g.jpg p-20050608-AJYW-m.jpg p-20050608-AJYW-v.jpg p-20050608-AJYW.jpg While of course keeping the lowercase prefix (p-) and suffix (-g /-m / -v) and the lowercase file extension (.jpg) I hope this is clear and that someone can help with this, Thanks, Steve |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Use awk
for old_name in `ls -l path_to_dir/*jpg`
do new_name=`awk -F"-" 'BEGIN { OFS="-"} {$3=toupper($3);print $0}' $old_name` mv $old_name $new_name done Last edited by rahul123_libra; 06-28-2005 at 06:37 AM. |
|
#3
|
|||
|
|||
|
Something using sed:
for filename in *.jpg; do echo $filename | sed -e 's/Aiyd/AIYD/g' done |
|
#4
|
|||
|
|||
|
THis is for 1 particular case
Quote:
This is for 1 particular case ( aiyd ) and not for all the options Isnt it ? |
|
#5
|
||||
|
||||
|
Apart from that, how will you change the name of the file with a sed. It requires a mv very specifically.
-vino |
|
#6
|
|||
|
|||
|
Perfectly Agree,
But i could accomplish only that much with my knowledge of sed. Can anyone give a general one with sed. mv is taken for granted. for filename in *.jpg; do newname=`echo $filename | sed -e 's/Aiyd/AIYD/g'` mv $filename newname done |
|
#7
|
||||
|
||||
|
Quote:
Also, using $3 sometimes matches more than the 4 letter code (where there is no suffix). Perhaps try: Code:
for i in *.jpg
do
eval $(echo $i|awk '{printf "mv %s %s\n", $0,\
substr($0,1,11) toupper(substr($0,12,4)) substr($0,16)}')
done
|
||||
| Google The UNIX and Linux Forums |