MkIII_Supra
08-19-2010, 01:48 PM
I am trying to get this simple rename script to work. I have two standard file names in use. The first one is a csv file that looks like this:
Example: 201008.csv
The other file is a text file that looks like this:
Example: 201008 Dump Record.txt
There are several files like these and I want to rename them like this:
Example: 201008 2010-08-19(0945).csv
Example: 201008 Dump Record 2010-08-19(0945).txt
But the mv command keeps giving me this error:
$: ./bshFileNameTest
1
200901 2010-08-19 (1039).csv
mv: target `(1039).csv' is not a directory
1
200901 Dump Record
200901 Dump Record 2010-08-19 (1039).txt
mv: target `(1039).txt' is not a directory
1
Below is the main portion, what is missing are some preliminary steps. Anyhow I can't seem to figure this one out.
for file in *; do
if echo "$file" | grep -q '.csv$'; then
if expr length "$file" = 10; then
PRE=${file:0:6}
REN=$PRE$RENUB".csv"
mv $file $REN
fi
elif echo "$file" | grep -q '.txt$'; then
if expr length "$file" = 22; then
PRE=${file:0:18}
REN=$PRE$RENUB".txt"
mv $file $REN
fi
fi
done
Example: 201008.csv
The other file is a text file that looks like this:
Example: 201008 Dump Record.txt
There are several files like these and I want to rename them like this:
Example: 201008 2010-08-19(0945).csv
Example: 201008 Dump Record 2010-08-19(0945).txt
But the mv command keeps giving me this error:
$: ./bshFileNameTest
1
200901 2010-08-19 (1039).csv
mv: target `(1039).csv' is not a directory
1
200901 Dump Record
200901 Dump Record 2010-08-19 (1039).txt
mv: target `(1039).txt' is not a directory
1
Below is the main portion, what is missing are some preliminary steps. Anyhow I can't seem to figure this one out.
for file in *; do
if echo "$file" | grep -q '.csv$'; then
if expr length "$file" = 10; then
PRE=${file:0:6}
REN=$PRE$RENUB".csv"
mv $file $REN
fi
elif echo "$file" | grep -q '.txt$'; then
if expr length "$file" = 22; then
PRE=${file:0:18}
REN=$PRE$RENUB".txt"
mv $file $REN
fi
fi
done