In that case would you show us the entire script?
|
I have not included it in any other script at the moment, it is completely stand alone. The code that i copied into my post the other day includes the complete contents of the file.
|
In that case, how are you executing it as it will not run as is?
|
The script does run as is. It is in a file called renamefiles.sh which I marked as executable. I run the command line, type the command ./renamefiles.sh which causes it to run. When I run it, it runs, but for each line says [[ cannot be found. This is the code that I am using exactly:
for file in *.wav; do cnt=1; newfile="${file%% *}"; while [[ -f "${newfile}.wav" ]]; do newfile="${file%% *}_$((cnt++))"; done; mv "${file}" "${newfile}.wav"; done It has been doing what it is supposed to do, but kicking up that error for every line. In addition, it adds an extra .wav on the end of files that have already been renamed by it, leaving the filename 1112223333.wav.wav. |
What happens if you place the following as the first line in the file:
Code:
#!/bin/bash |
I've had similar requirements some days ago. The thread is here: http://www.linuxquestions.org/questi...rogram-908658/
I've done it with perl because the normal rename-tool cannot handle regexp. Additionally I've written a clean.pl script: Code:
#!/usr/bin/perl Hope that helps. Markus |
Grail:
When I added the #!/bin/bash into the file, it stopped giving the error of [[ cannot be found. It does still add the unnecessary .wav at the end of the files. Markush: I will have to look into your script. I am not familiar with PERL at all, but I have a couple of books (Llama and camel) on the way to start picking it up. I have been doing so much programming lately at my job that I need to pick it up as BASH is great, but PERL seems to be a bit more powerful. |
Quote:
Quote:
then the following two line: Code:
newfile="${file%% *}"; Code:
mv "${file}" "${newfile}.wav"; |
Grail:
What I mean by the unnecessary .wav is that when any file which has already been through the scripted process once is still in the folder when the script is run again has a .wav appended to the end. |
Quote:
has been run once) it will not produce the desired results. Original format (as you described it): Code:
2033028167 by xxxxxx@xxxxxx @ 4_32_36 PM.wav Code:
2033028167.wav Code:
for file in *.wav; # Assume we are up to our changed file, then file = 2033028167.wav |
Thank you for the clarification, I really appreciate it. Given the situation, it is probably easiest just to move the file into a different folder as it is renamed, so that there are never any that have been renamed already.
Thanks again grail! You have been a lot of help! |
All times are GMT -5. The time now is 03:01 AM. |