Replace strings based on position and length?

Suppose i have a file which contains thousands of records. e.g adjgmptjadmwpgjmwmd i need to replace the string from 3rd to 8th position using awk script in entire file. And also the positions will be passed as parameter.

awk supports a substr(var,x,y) function...to which you could variable-ize the x and y, but are you intending a wholesale replacement of these columns, or more of a pattern-based replacement?

Or use sed, e.g.

sed "s/^\(..\)....../\1$var/" infile

Example:

$ var=abcdef
$ echo 123456789|sed "s/^\(..\)....../\1$var/"
12abcdef9

awk -v a=0 -v b=8 '{print substr($0,0,a)"."substr($0,b)}'

im trying like this replace a string based on position
"unix" instead of "." and i need to pass unix as parameter.
how to pass it?

---------- Post updated at 05:46 PM ---------- Previous update was at 04:29 PM ----------

can anyone pls suggest?