|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Change file names
I have this problem.
I download a huge number of images from a central source in a big zip file. They don't seem to care about the fact that our linux machine is case sensitive and their NT box is not. They alternate ending the file name with .JPG and .jpg. Does anyone know how to write a shell script that would rename them all to use the .JPG ending. The files are all named like this -> 100211.jpg or 100211.JPG There are about 40,000 images all in one directory. Andrew P.s. I am using a bash shell Last edited by agray : October 29th, 2001 at 01:20 AM. |
|
#2
|
|||
|
|||
|
#!/bin/sh
img_dir=/path/to/image_dir cd $img_dir for image in * do lc_image=`echo $image | awk '{print tolower($0)}'` mv ./$image ./$lc_image done 1) Alter the img_dir path and that is it 2) Copy this script to anywhere except img_dir itself 3) Chmod this script 700 and run it like so: ./script.sh |
|
#3
|
|||
|
|||
|
Thanks so much that worked great
Andrew I added a little error handling, but how would I get it to ignore files that are already upper case #!/bin/sh img_dir=$1 if [ -d $img_dir ] then cd $img_dir for image in * do lc_image=`echo $image | awk '{print toupper($0)}'` mv ./$image ./$lc_image done else echo " $1 not a dir" fi Last edited by agray : October 29th, 2001 at 08:15 PM. |
|
#4
|
|||
|
|||
|
>> to ignore files that are already upper case
That's ignored by default. |
|
#5
|
|||
|
|||
|
hi, im a newbie,
how do i list proper names appearing in a text and how do i change to a different text file.any help?? ![]() |
|
#6
|
|||
|
|||
|
Could you explain in a little more detail (and a little clearer?) what you need?
|
|
#7
|
|||
|
|||
|
Hi,
I have a bunch of files (literally 100s) that look something like this 98765432-2000up.txt or like this 98765432.200up.txt For each file the first eight digits are a unique number and then ALL the files are either -2000.txt or .2000.txt What I want to do is delete the -2000 and the .2000 part of each file so that each file is changed to its unique number with a .txt extension, something like this >>> 98765432.txt I've looked through this board and have tried a few things but nothing seems to work, I'm a beginner at this. A separate script for each situation is what I need (because the -2000.txt files are in one location and the .2000.txt files are in another) Any help would be greatly appreciated. Thanks! |
|
#8
|
|||
|
|||
|
Quote:
something like Code:
rename '-2000' '' *-2000.txt rename '.2000' '' *.2000.txt |
|
#9
|
|||
|
|||
|
Quote:
Uhmmmmm, I tried that and I couldn't get it to work. I was thinking something along the lines of >>> ls -1 sd.* | sed -e 's/sd.\(.*\)/mv "&" \1/' | sh I used the above script to delete the sd. from the beginning of each file. Now I need to get rid of the -2000 and the .2000 so i have a files named like this >>> unique_8_digit_num.txt Something more specific would be great!!! |
|
#10
|
|||
|
|||
|
If you are sure of the format of the filenames:
Code:
for fn in $(ls -1) do newfn="$(echo $fn | cut -c1-8).txt" mv $fn $newfn done |
|
#11
|
|||
|
|||
|
Quote:
That works GREAT! Thank you! |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Change file names |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|