Hi,
I want to check all files in a folder for some specific start string and append all matching filenames with _1, _2 .... for each file found in the directory.
But, $file below gives me all details of the files like access permissions, owner and filename etc. I just want all the filenames and I hope the blow code shoudl work ??
i=1
for file in `ls -l |grep "$filename"`
do
echo "$file"
mv $file $file_i
i=`expr $i + 1`
done
Kindly help.
Chetan Vyas
[/FONT]
i=1
for f in "$filename"*; do
printf '%s\n' "$f"
mv -- "$f" "$f"_$i
i=$(( i + 1 ))
done
This was what i was trying to do. Now i have done picking up the filenames and renaming all of them in a loop.
Code:
i=0
for file in `ls |grep "$filename"`
do
echo "$file"
echo $i
i=`expr $i + 1`
mv /var/tmp/akk2/${file} /var/tmp/akk2/${file}_${i}
done
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Thank You.
The UNIX and Linux Forums