|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > need tcsh command line script to rename files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|