renaming files with spaces and special characters.
I have several files that are dumped into a directory on a linux box on a nightly basis. I need to rename all of files the in the directory with a script that runs each morning.
Here is an example of the file names: MYReport Report crtjan0921-31 (3797 found).csv I would like files in this format to be renamed to: crtjan0921-31.csv any help will be greatly appreciated. |
The general answer is that you have to quote a filename that contains spaces (or any character that has special meaning to bash)
Here's a sample of what works and what does not: Code:
[mherring@hplap play]$ touch "file name" |
And here is something that might work:
Code:
for file in MYReport* |
Quote:
Code:
# ls -1 alternatively, Code:
ls -1 *csv | awk 'BEGIN{FS="[. ]";q="\047"} |
Quote:
I enter this; # python filerenamer.py -p "^.* .* (crt.*) \(.*$" -e "\1.csv" -l "*.csv" I get the following output but file names are not changed. Is there something that I have to specify in order to actually update the files name? ==>>>> [ /var/www/kb_file/newdata/MYReport Report crt2009apr1-10 (3613 found).csv ]==>[ /var/www/kb_file/newdata/crt2009apr1-10.csv ] ==>>>> [ /var/www/kb_file/newdata/MYReport Report crt2009feb1-10 (4115 found).csv ]==>[ /var/www/kb_file/newdata/crt2009feb1-10.csv ] ==>>>> [ /var/www/kb_file/newdata/MYReport Report crtjan0911-20 (3156 found).csv ]==>[ /var/www/kb_file/newdata/crtjan0911-20.csv ] ==>>>> [ /var/www/kb_file/newdata/MYReport Report crt2009jan1-10 (2478 found).csv ]==>[ /var/www/kb_file/newdata/crt2009jan1-10.csv ] ==>>>> [ /var/www/kb_file/newdata/MYReport Report crtjan0921-31 (3797 found).csv ]==>[ /var/www/kb_file/newdata/crtjan0921-31.csv ] Thanks for your help!! |
Did you try the script I suggested ?
|
Just tried the script you suggested...
Quote:
Thank you very much |
for each file whose name starts with MYReport,
extract the third word from the file name and make that the "target" variable. If no file already exists with "target" as its name and ".csv" as its suffix, rename the original file to it. |
Quote:
Code:
# python filerenamer.py -p "^.* .* (crt.*) \(.*$" -e "\1.csv" "*.csv" |
All times are GMT -5. The time now is 12:38 PM. |