Script to change file contents line by line

Hi,
I'm struggling to write a script to do the following,

-will go through each line in the file
-in a specific character positions, changes
the value to a new value
-These character positions are fixed througout the file
-----------------------
e.g.: file1.sh will have the following 3 lines,

line1 aaaa xxxx
line2 bbbb yyyy
line3 cccc zzzz

After executing the script, content of file1.sh should be,

line1 a1aa xx4x
line2 b1bb yy4y
line3 c1cc zz4z
-----------------------

Thanks a ton in advance
Vini

Hope this helps:

sed '
h
s/^.\{8\}\(.\).*/\1/
y/abcdefghijklmnopqrstuvwxyz/11111111111111111111111111/
G
s/\(.*\)\n\(.\{8\}\).\(.*$\)/\2\1\3/
h
s/^.\{13\}\(.\).*/\1/
y/abcdefghijklmnopqrstuvwxyz/44444444444444444444444444/
G
s/\(.*\)\n\(.\{13\}\).\(.*$\)/\2\1\3/' foo

Sample:

$ sed '
> h
> s/^.\{8\}\(.\).*/\1/
> y/abcdefghijklmnopqrstuvwxyz/11111111111111111111111111/
> G
> s/\(.*\)\n\(.\{8\}\).\(.*$\)/\2\1\3/
> h
> s/^.\{13\}\(.\).*/\1/
> y/abcdefghijklmnopqrstuvwxyz/44444444444444444444444444/
> G
> s/\(.*\)\n\(.\{13\}\).\(.*$\)/\2\1\3/' foo
line1 aa1a xx4x
line2 bb1b yy4y
line3 cc1c zz4z

Also, you can save this to a file:

h
s/^.\{8\}\(.\).*/\1/
y/abcdefghijklmnopqrstuvwxyz/11111111111111111111111111/
G
s/\(.*\)\n\(.\{8\}\).\(.*$\)/\2\1\3/
h
s/^.\{13\}\(.\).*/\1/
y/abcdefghijklmnopqrstuvwxyz/44444444444444444444444444/
G
s/\(.*\)\n\(.\{13\}\).\(.*$\)/\2\1\3/

And the run it by:

sed -f foo.sed foo

Hi Angheloko,

Thanks a lot for the response.
After digging through the net and "sed" man pages came up with the following,
--------------------
sed -e "1n; s/./1/2" -e "s/./4/8" file1.sh > file2.sh
mv file2.sh file1.sh
--------------------

This is giving me the required output & I'm doing some testing on the same.

Thanks Again
Regards
Vini

:eek: Genius man! Good to know you got it. It ended up me leaning something new. I should thank you! :b:

� Live as if you were to die tomorrow. Learn as if you were to live forever. �
-Mahatma Gandhi

Cheers Mate