Hi All,
Firstly thanks pixellany and jschiwal for your encouragement.
And secondly I am currently trying the method suggested by jschiwal I will update here asap once i tried with that method. From the first glance i think it might solve the problem i am having right now [not sure yet
].
Anyway, thirdly, I just reliased that my input file (i.e file1) has metacharacters in it. The location of the metacharacters varies. So I have a mixed up input file1 that look like this:
file1
a+b=c+d 1e105
g+h=o+p abcdefg
rev/ 0.35 / h 35/
h2 / 20 / he / ar
file2
a+b=c+d 1e105
x+y=z+s 5e105
g+h=o+p abcdefg
t+r=w+q xvyderf
rev/ 0.35 / h 35/
h2 / 20 / he / ar
and my output should look like this as mentioned before
!a+b=c+d 1e105
x+y=z+s 5e105
!g+h=o+p abcdefg
t+r=w+q xvyderf
!rev/ 0.35 / h 35/
!h2 / 20 / he / ar
So the problem here is that when this "/" thing comes into the picture i am getting this error when i use previously posted command.
sed: -e expression #1, char 7: unknown command: `3'
sed: -e expression #1, char 7: unknown command: `3'
sed: -e expression #1, char 59: unknown command: `F'
sed: -e expression #1, char 11: extra characters after command
Hence I tried other method such as including "",'',and /\ but all did not work. I reffered websites get the sed manual. But the problem is that most of the example is to find singular thing in multiple files. eg s/samba/Mamba/g. SO they know what they looking for and where will the metacharacter will be present but this not for my case.
Example of failed method:
#!/bin/sh
while read line; do
sed "/$line/"s/"'$line'"/"'!$line'"/g file2
done < file1
Example2
#!/bin/sh
while read line; do
sed "#$line#s#$line\/#!$line\/#g" file2
done < file1
Example 3 [even tried this method but not enough experience I guess
]
#!/bin/sh
while read line; do
sed {
if ( $line !=rev, $line !=Low, $line !=troe ) then
"/$line/s/$line/!$line/g" file2
else "#$line#s#$line\#!$line\#g" file2
fi
done < file1
For the problem I notice is that I need the "" for the sed to able to lacate the line and if i introduce '' it is disabled hence it cant locate the line to replace. How could I have the both option ON such that it can locate the line and reads the line as whole thing (h2 / 20 / he / ar) by ignoring "/"?
Thanks in advance