UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 29th, 2001, 01:17 AM
agray agray is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Chapel Hill, NC
Posts: 21 agray User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old October 29th, 2001, 05:24 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
#!/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

Reply With Quote
  #3  
Old October 29th, 2001, 08:11 PM
agray agray is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Chapel Hill, NC
Posts: 21 agray User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old October 29th, 2001, 09:01 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> to ignore files that are already upper case

That's ignored by default.

Reply With Quote
  #5  
Old April 12th, 2006, 04:28 AM
jojo04 jojo04 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 1 jojo04 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 38 sec
Reputation Power: 0
Question change to a different text file

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??

Reply With Quote
  #6  
Old April 27th, 2006, 08:05 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Novice (500 - 999 posts) Click here for more information
 
Join Date: Mar 2006
Posts: 728 SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 4 h 30 m 11 sec
Reputation Power: 315
Could you explain in a little more detail (and a little clearer?) what you need?

Reply With Quote
  #7  
Old July 27th, 2006, 07:13 PM
mswartz mswartz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 14 mswartz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 35 m 57 sec
Reputation Power: 0
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!

Reply With Quote
  #8  
Old July 27th, 2006, 07:37 PM
spoon! spoon! is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 247 spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 8 h 15 m 23 sec
Reputation Power: 77
Quote:
Originally Posted by mswartz
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!

something like
Code:
rename '-2000' '' *-2000.txt
rename '.2000' '' *.2000.txt

Reply With Quote
  #9  
Old July 27th, 2006, 08:15 PM
mswartz mswartz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 14 mswartz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 35 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by spoon!
something like
Code:
rename '-2000' '' *-2000.txt
rename '.2000' '' *.2000.txt



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!!!

Reply With Quote
  #10  
Old July 28th, 2006, 04:08 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Novice (500 - 999 posts) Click here for more information
 
Join Date: Mar 2006
Posts: 728 SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 4 h 30 m 11 sec
Reputation Power: 315
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

Reply With Quote
  #11  
Old July 28th, 2006, 03:39 PM
mswartz mswartz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 14 mswartz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 35 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by SimonJM
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



That works GREAT! Thank you!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Change file names


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway