character substitution

Hi ,
I have a problem , I need to devlope a script where in the user inputs file name , line number , and character position , and a substitution variable , the character at that character position should be substituted by the substitution value
for ex
say i have a file
abc.txt
which has a line 1 as "vivek is a good boy"
If i input line number 1
character podition 7-8
substitution value : ok
the output should be "vivek ok a good boy "

need help

$ cat abc.txt
vivek is a good boy
unix.com
shell programming forum

Replace character position 7-8 with "ok" in 1st line of abc.txt, here is the way using sed:

$ sed -r "1 ~ s/^(.{6})(.{2})/\1ok/" abc.txt > abc.txt.tmp; mv abc.txt.tmp abc.txt

$ cat abc.txt
vivek ok a good boy
unix.com
shell programming forum

//Jadu

Hi,

Try follow one. There is five input, first is the file to be dealed with. Second is the line number of the file. Third is the begin position of string to be replaced. Forth is the length of the string to be replaced. Fifth is the value used to replace old one.

file=$1
line=$2
char=$3
len=$4
val=$5
nawk -v l="$line" -v c="$char" -v len="$len" -v v="$val" '{
if(NR==l)
	print substr($0,1,c-1) v substr($0,c+len)
else
	print $0
}' $file > ${file}.bak
rm $file
mv ${file}.bak $file
awk 'BEGIN{
   printf "Enter line number: "
   getline linenum < "-"
   printf "Character position eg 2-3: "
   getline chpos < "-"
   printf "Substituion  value eg :" 
   getline subval < "-"
   if ( chpos ~ /-/  ) {
    n=split( chpos, charpos,"-")
    startpos = charpos[1]
    endpos=charpos[2]
   }else {
    startpos=chpos
    endpos=""
   }
}
NR==linenum{
   sub( substr($0,startpos,endpos) , subval)   
}
1' "file"