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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 25th, 2003, 11:44 PM
miselaineeous miselaineeous is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: NYC
Posts: 1 miselaineeous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
need tcsh command line script to rename files

I have a large number of text files with characters I'd like to replace such as "/" and "&" with "_". I would also like to add the .txt extension. Does someone know the best way to do this from the command line in the Mac OsX shell (tcsh)?

Thank you so kindly,
-E

Reply With Quote
  #2  
Old January 25th, 2004, 11:02 AM
samsm's Avatar
samsm samsm is offline
got the bounce bounce
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 47 samsm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 54 sec
Reputation Power: 6
I found this:
http://lab.artlung.com/other/unix-batch-file-rename/

Code:
% more t.sh
for i in * ; do
echo mv \"$i\" \"$i.mp3\" | sh
done

Reply With Quote
  #3  
Old February 4th, 2004, 08:48 AM
Ludootje Ludootje is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 49 Ludootje User rank is Corporal (100 - 500 Reputation Level)Ludootje User rank is Corporal (100 - 500 Reputation Level)Ludootje User rank is Corporal (100 - 500 Reputation Level)Ludootje User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 7 h 34 m 3 sec
Reputation Power: 8
The script sam posted won't work. It's for bash and it adds a '.mp3' extensions to a file, that's all it does.

This works only in bash, not tcsh, but AFAIK OS X ships both, it just uses tcsh as the default.

for FILE in *; do mv $FILE $(echo $FILE | sed -e 's/&/_/').txt; done

This will require sed though.
I don't see how a file could possibilty have a '/' in its name, but in case with OS X it's possible, this should fix it:
for FILE in *; do mv $FILE $(echo $(echo $FILE | sed -e 's/&/_/') | sed -e 's/\//_/').txt; done

(if you the 2nd script, there's no need to run the first)

I'm not using GNU/Linux right now so I can't check itt out, but I think it should work...
BTW to find bash:
whereis bash
which bash

Then once you have:
/path/to/bash copy the script I typed here

Or just put the one-liner in a file, and enter this as the first line of the file:
#!/path/to/bash

then, make the file executable:
chmod +x filename.sh
and run it: ./filename.sh
__________________
Disclaimer: the owner of this post is NOT responsible for any moral and/or physical damage this post could cause to you.

Reply With Quote
  #4  
Old May 28th, 2004, 09:11 PM
candyman660 candyman660 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 candyman660 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ludootje how would you go about renaming all the files from say test1 or test1.txt to test1$DATE test1$DATE.txt?

I need to go through all files in a directory either a single level or recursivly and place a date and time stamp before the .extension if there is one. If there is no .extension then the date would just be appended to the end. As well this need to work for hidden files that start with .

Are you able to help

oh ya needs to work in bash

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > need tcsh command line script to rename files


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





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