for loop other file with same name and different extension

Hi Friends,

I am using the following command

for i in `ls $PWD`; do cat $i > test && mv test $i; done

But, I want to execute another command and write the output to another file with different extension but same name, like this

I tried using this

for i in `ls $PWD`; do cat $i > $i.html; done

But, this doesn't work

Any thoughts

ls already lists the contents of the current directory; there's no need to use $PWD .

The safest way to generate a lexicographically-sorted list of a directory's contents for a for-loop is to use * and pathname expansion (aka globbing). Using ls without any options is both pointless and fragile.

A file extension can be omitted with the following parameter expansion operation: ${i%.*}

That should get you there.

Regards,
Alister

for i in `ls $PWD`
do 
cat $i > $i.html
new_file=`echo $i.html | awk -F"." '{print $1"."$3}'`
mv $i.html $new_file
done