Quote:
|
Originally Posted by davidcollins001
I am trying to write a script that will take a list of filenames, operate on them individually and output a changed file name - mainly for renaming a large number of files.
So far I have
TARGET="$(ls -1 |)"
for FILE in "$TARGET"; do
NEW=$(echo "$FILE" | 'do some stuff to file')
mv $FILE $NEW
done
but all the filenames are kept as one long string in $FILE, and $NEW, so I can't do anything with them once I have changed them. How can I get the script to see each filename separately?
Thanks
|
**************************
for file in `ls -l|grep "^-"|awk '{print $9}'`
do
# do whatever u want to do on file
echo $file
#1st option
echo $file>${file}Newname
#2nd option
mv $file newfile
done
**********************
ur code seems correct except $NEW ,bcz if u allready defined NEW as a variable then it will alws take the constant value of that variable ..which is defined before the loop