Tcsh script - sed command for special characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tcsh script - sed command for special characters
# 1  
Old 03-31-2017
Tcsh script - sed command for special characters

Hi,

I am using sed command to replace following line in gz file-
Code:
sed -n 's/""COS_12_TM_1" ( 1101110101001001010011110100000010110100010010000000100000000010XX010000000 )"/""COS_12_TM_1" ( 110111010100100101001111MM00000010110100010010000000100000000010XX010000000 )"/g' filename.gz


Code:
$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-
Code:
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!!!


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-31-2017 at 06:05 AM.. Reason: Added CODE tags.
# 2  
Old 03-31-2017
Quote:
Originally Posted by Preeti Chandra
eg. sed 's/$x/$y/g'
Can anyone tell me correct way to do this.Because it is not working.
It is not woring because the quoting prevents the expansion of the variables. When you write

Code:
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:

Code:
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
# 3  
Old 03-31-2017
And no backticks here
Code:
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.
# 4  
Old 04-03-2017
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].
# 5  
Old 04-03-2017
Moderator's Comments:
Mod Comment Please open a new thread to discuss a new topic.

Please use CODE tags (as required by forum rules) when displaying sample input, sample output, and code segments.

This thread is closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed special characters issues

I am dusting off the sed cobwebs and had a basic question: I have a file that contains: $firewall = "on"; $cache = "on"; $dataset{'mary had a little lamb'} = "on"; and want to only change the contents of what is between the single quotes: $dataset{'big bad wolf'} = "on"; I... (3 Replies)
Discussion started by: metallica1973
3 Replies

2. Shell Programming and Scripting

sed special characters issue

Hi I'm trying to replace string1 by string2 in file homepage.htm as follows but is not working. Please Help: sedsed -i "s@'://your server name:port/test/owa'@'://11.22.33.44:5555/pls/SAMPLE'@g" homepage.htm Where, String1 ://your server name:port/test/owa String2... (3 Replies)
Discussion started by: koazter
3 Replies

3. Shell Programming and Scripting

Escape special characters in SED

Need help in escaping special characters in sed command. Here is the the string which i am trying to find a replace with From :- REQUEST_TYPE=PIXEL&MSG_ID={//MESSAGE_ID} To :- REQUEST_TYPE=PIXEL&MSG_ID= X_EDELIVERY_MESSAGE_ID & BATCH_ID= X_EDELIVERY_BATCH_ID Here is the sed command i am... (2 Replies)
Discussion started by: aakishore
2 Replies

4. Shell Programming and Scripting

Need help with sed to escape special characters

Hello Everyone, I need to read an encrypted password from the user and update that value in an xml file. I am trying to use "sed" for searching the appropriate tag and replacing this new value that get from the user. Since the encrypted password can contain special characters(like /,\,&,etc),... (4 Replies)
Discussion started by: majose
4 Replies

5. Shell Programming and Scripting

SED with Special characters

Hello All Seeking the right one SED command. My attempt is: From orginal.txt by SED to target.txt sed -i "/('outbound-callerid/a\$ext->add($context, $exten, '', new ext_SipAddHeader('P-Preferred-Identity', '<sip:${CALLERID(nummer)}@carrier.com>'));" orginal.txtWhat am make wrong?:wall: ... (5 Replies)
Discussion started by: mdbinder
5 Replies

6. Shell Programming and Scripting

Using sed to replace special characters

Hi everyone I have file1 contains: '7832' ' 8765 6543 I want a sed command that will format as: '7832' , '8765' , '6543' I tried sed -e s/\'//g -e 's/^*//;s/*$//' file1 > file2 sed -e :a -e '$!N; s/\n/ /; ta' file2 which gives: 7832 8765 6543 I need some help to continue with... (5 Replies)
Discussion started by: nimo
5 Replies

7. Shell Programming and Scripting

SED script to backslash special characters

I have a shell script that I have written to be a kind of to-do/notepad that's quickly executable from the command line. However, special characters tend to break it pretty well. Ie: "notes -a This is an entry." works fine. "notes -a This is (my) entry." will toss back a bash syntax error on... (5 Replies)
Discussion started by: skylersee
5 Replies

8. Shell Programming and Scripting

sed with many special characters

I started with this: counter1=1 cp file.txt file_${counter1}.tmp while read name1 do echo $name1 counter2=`expr $counter1 + 1` sed /'${name1}'/d file_${counter1}.txt > file_${counter2}.txt counter1=`expr $counter1 + 1` done < source.txtsource.txt contains the... (1 Reply)
Discussion started by: lakanino
1 Replies

9. Shell Programming and Scripting

sed with special characters

Hi, I am reading a file (GC_JAR.log) which has entries like: 511725.629, 0.1122672 secs] 525268.975, 0.1240036 secs] 527181.835, 0.2068215 secs] 527914.287, 0.2884801 secs] 528457.134, 0.2548725 secs] I want to replace all the entries of "secs]" with just "secs" Thus, the output... (4 Replies)
Discussion started by: itzz.me
4 Replies

10. Shell Programming and Scripting

awk/sed with special characters

i have this script that searches for a pattern. However it fails if the pattern includes some special characters. So far, it fails with the following strings: 1. -Cr 2. $Mj 3. H'412 would a sed or awk be more effective? i don't want the users to put the (\) during the search (they... (5 Replies)
Discussion started by: apalex
5 Replies
Login or Register to Ask a Question