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 "
$ 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
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.