Tcsh script - sed command for special characters

Hi,

I am using sed command to replace following line in gz file-

sed -n 's/""COS_12_TM_1" ( 1101110101001001010011110100000010110100010010000000100000000010XX010000000 )"/""COS_12_TM_1" ( 110111010100100101001111MM00000010110100010010000000100000000010XX010000000 )"/g' filename.gz
$x= ""COS_12_TM_1" ( 1101110101001001010011110100000010110100010010000000100000000010XX010000000 )"
$y=""COS_12_TM_1" ( 110111010100100101001111MM00000010110100010010000000100000000010XX010000000 )"

eg. sed 's/$x/$y/g'
Can anyone tell me correct way to do this.Because it is not working.
Both the strings $x and $y are present in different files($x in list and $y in Masked_list).
Also need help in using nested foreach loop ,Following is the script I am trying to run-

set x=`cat list`
set y=`cat Masked_list`
foreach org ( $x )
echo "$org" >> list_1
    foreach masked ( $y )
            echo "$masked" >> list_2
        `sed -n 's/$org/$masked/g' lw20_82_55_ac_0x19E1.wgl.gz` >> new_wgl
        set tmp_2=`grep $org new_wgl`
         if ( $tmp_2 == " " ) then
            echo "Flip Flop MAsekd in the Original WGL File"
     end
        endif
end

Thanks in advance!!!

It is not woring because the quoting prevents the expansion of the variables. When you write

command $VAR something

you expect the string "$VAR" to be replaced by the content of the variable VAR - this is called "expansion" and the quotation in single-quotes was invented to prevent exactly this. (The prevention of variable expansion is the big difference between single- and double-quotes.) Therefore:

sed 's/'"$x"'/'"$y"'/g'

should work. Notice that this might still not do what you want it to do because the variables content could hold characters with a special meaning to sed (like "*", "/", etc.), but this is a different kind of error.

I hope this helps.

bakunin

And no backticks here

sed -n 's/'"$org"'/'"$masked"'/g' lw20_82_55_ac_0x19E1.wgl.gz >> new_wgl

tcsh is problematic - use bash (or zsh or ksh) instead! The syntax is different, but it is worth to learn it.
I see .gz and hope it's not a compressed file. That would give you an additional problem, like corrupting the file so cannot be uncompressed.

Thank you guys...It is working now..

---------- Post updated at 02:05 AM ---------- Previous update was at 01:51 AM ----------

One more question:
I want to grep"COS_12_TM_4 pattern from a file look likes :

"COS_12_TM_4" [
"dummy_COS_12_1_TM_4",
"dummy_COS_12_2_TM_4",
"dummy_COS_12_3_TM_4",
"dummy_COS_12_4_TM_4",
"dummy_COS_12_5_TM_4",
"dummy_COS_12_6_TM_4",
"dummy_COS_12_7_TM_4",
"dummy_COS_12_8_TM_4",
"dummy_COS_12_9_TM_4",
"dummy_COS_12_10_TM_4",
"dummy_COS_12_11_TM_4",
"dummy_COS_12_12_TM_4",
"dummy_COS_12_13_TM_4",
"dummy_COS_12_14_TM_4",
"dummy_COS_12_15_TM_4",
"dummy_COS_12_16_TM_4",
"dummy_COS_12_17_TM_4",
"dummy_COS_12_18_TM_4",
"dummy_COS_12_19_TM_4",
"dummy_COS_12_20_TM_4",
"dummy_COS_12_21_TM_4",
"dummy_COS_12_22_TM_4",
"dummy_COS_12_23_TM_4",
"dummy_COS_12_24_TM_4",
"dummy_COS_12_25_TM_4",
"dummy_COS_12_26_TM_4",
"dummy_COS_12_27_TM_4",
"dummy_COS_12_28_TM_4",
"dummy_COS_12_29_TM_4",
"dummy_COS_12_30_TM_4",
"dummy_COS_12_31_TM_4",
"dummy_COS_12_32_TM_4",
"dummy_COS_12_33_TM_4",
"dummy_COS_12_34_TM_4",
"dummy_COS_12_35_TM_4",
"dummy_COS_12_36_TM_4",
"scan_out[5]" ];

I am taking scan_out[5] as the input from the user.
From the above file how to grep "COS_12_TM_4" this string which is corresponding to the input scan_out[5].

Moderator comments were removed during original forum migration.