hi ,
I have certain files at the same path with differeent extensions like .dat , .txt etc ...........i need to rename them with extension .found at the same path with the help of loop....
also the files names will be like this ;
abc_2010_c1.dat
abc_2010_c2.dat
xyz_2010_c1.txt
Hi,
I have just print the mv command, u can modify according your requirement.
#!/bin/sh
ls | while read first_file
do
ext=`echo $first_file | awk -F'.' '{print $2}'`
bsnm=`basename $first_file ".$ext"`
echo "mv $first_file $bsnm.found"
done
@thegeek: use rename command
The rename utility is not available on all systems.
More possibilities:
for i in *
do
mv ${i} ${i%.*}.found
done
with sed:
ls *|sed 's/\(.*\)\..*/mv & \1.found/' | sh
with awk:
ls * | awk -F\. '{system("mv " $0 " " $1 ".found')}'