Help, | ! & [ ^ in sed

Hi,everyone:
I'm new to shell, and I'm confued with some script:

ssum=`echo "$lsum" | sed 's|!|\\\\!|g'`
line1=`echo "$line" | sed 's!\[!\\\[!g' | sed 's!\]!\\\]!g'`
line3=`echo "$line2" | sed 's!\&!\\\&!g'`
sed "s^${line3}^${newline3}^g" ${TIER4FILE} > ${TMP_TIER4FILE}
In the first three lines, I'm not sure the "|","!","[" usage. I only know that "!" is used to inverse the action of a command. And is "s" here used to exchange strings?

In the last line, "s" is used as exchange command, but I don't understand the usage of "^".

:confused:Could anyone help me? Thanks?

in sed the substitute command can be written in many syntax:-

example:

sed 's/old pattern/new pattern/g'    #  g means substitute globally.

sed 's!old pattern!new pattern!g'   # same result as above

sed 's^old pattern^new pattern^g'    # also same result as above

sed '_old pattern _new pattern_g'  # also same result 

BR

To ahmad.diab:
Thanks.

But in

sed 's|!|\\\\!|g'`

what does "|" mean?

because ! is a special char. you need to escape it by "\" if you want to search for it ... if you didn't scape it the system will see it as a negate (not) char .
BR

A substitution requires two parts: the part you want to replace; and the part you want to replace it with. These parts are separated by a character that you chose. So after the "s" you say what the delimiting character should be:

s|original_string|new_string|

would use a | as the delimeter. This could be almost any character:

Most people use a /, but for example if the expression you want to replace, or the one you want to replace it with contains slashes, then it's convenient to use something else:

s+original_string+new_string+
sXoriginal_stringXnew_stringX

It's all the same thing.

Thanks all.

---------- Post updated at 08:36 PM ---------- Previous update was at 09:01 AM ----------