Sed problem

Hi guys,

I have a problem where by I need to remane a file by moving it to another location. For instance I have a file called
change.txt
changeA.txt
changeB.txt
and I need to change the name to
change_a1.txt
changeA_a2.txt
changeB_a3.txt

I need a sed regular expression that changes the name i.e. basically before the dot put _a1 and then put .txt again.

any help pls

Sed is not what you want to use. There is an example of a shell script which does what you describe as wanting to do.

#!/usr/bin/ksh

typeset -i num=0

TMP=file.$$

cat <<EOT >$TMP
change.txt
changeA.txt
changeB.txt
EOT

while read filename
do
    num=$((num + 1))
    newfile="${filename%.*}${num}.${filename#*.}"
    echo $filename $newfile
done < $TMP

rm $TMP
exit 0

This Will work but am not sure whether it meets ur requirements...

awk -F"." '{printf("%sa%s.%s\n",$1,i++,$2)}' filename

Regards,
aajan

awk 'BEGIN{FS=".";n=1}
{
print $1"_a"n"."$2
n=n+1
}' filename