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,
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/
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.