replace word with special charaters


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users replace word with special charaters
# 1  
Old 10-19-2009
replace word with special charaters

I have input file called file1 with characters that have \\ in it.
I cannot change input file, because it is generated earlier in script.
Now would like to replace string on line in file called bfile with output from file1
I have been using sed command.
Code:
$cat file1
pc//6sPxp==
$ cat scr1
#!/bin/ksh
BC=`cat file1`
sed -e "s/State/$BC/g" bfile
$ ./scr1
sed: command garbled: s/State/pc//6sPxp==/g


Last edited by pludi; 10-19-2009 at 05:44 PM.. Reason: code tags, please...
# 2  
Old 10-19-2009
Ok
Will do this next post, sorry.
# 3  
Old 10-19-2009
You should use another character as a delimiter in sed command:
Code:
sed -e "s%State%$BC%g" bfile

instead of:
Code:
sed -e "s/State/$BC/g" bfile

for example... You may choose a character that is not in the file whose contents is to be changed, though; in fact, this is the explanation of the error message that you include in your request.
# 4  
Old 10-20-2009
Yes, that worked!
Thank you hexram!
I thought I was going to have to write a sub routine to analyze file1 character by character.
I not sure what other delimiter I could use? Ok read man page. "Any character other than backslash or newline can be used instead of a slash to delimit the RE and the replacement."
I will change code to look at output from generated file1 and make changes to sed command, if file1 has /, %, $, etc.... in it.
# 5  
Old 02-24-2010
MySQL

you want to change your log file content "\\" to some special character or any characters,
you can try this by using the following example code;

Code:
sed -e "s/[\]/-/g"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to replace special characters?

Hi Team, I have data like this. |*|.5|*|0.2|*|A.B|*| Would like to add zero (0) before the decimal point where there is no zero as |*|0.5|*|0.2|*|A.B|*| How to replace |*|. with |*|0. I tried below command which didn't work echo '|*|.5|*|0.2|*|A.B|*' | sed... (4 Replies)
Discussion started by: Ravi.K
4 Replies

2. Shell Programming and Scripting

How do i replace a word ending with "key" using awk excpet for one word?

echo {mbr_key,grp_key,dep_key,abc,xyz,aaa,ccc} | awk 'gsub(/^|abc,|$/,"") {print}' Required output {grp_key,xyz,aaa,ccc} (5 Replies)
Discussion started by: 100bees
5 Replies

3. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

4. UNIX for Dummies Questions & Answers

Find and replace mulitple charaters in filenames

I have a virtual pdf printer set up on my server which produces files with the following prefix: smbprn_00000044_Microsoft_Word_-_OriginalFilename.pdfthe number in the center of the file increase by one for each new file. I want to remove all the charaters infront of OriginalFilename.pdf using... (14 Replies)
Discussion started by: barrydocks
14 Replies

5. Shell Programming and Scripting

How to replace special characters?

Hi Unix Guru, I have an requirement for replace some specail characters in a file, my file came from mainframe. please see below example: when open it with vi 17896660|89059215|04/24/1998 00:00:00.000000| abc 123-453-1312^M<85>^M<85>|124557 if I run cat -v I got following:... (25 Replies)
Discussion started by: ken002
25 Replies

6. Shell Programming and Scripting

Replace special characters

I have a line ending with special character and 0 The special character is the field separator for this line in VI mode the file will look like below, but while cat the special character wont display i know the hexa code for the special character ^_ is \x1f and ascii code is \0037, ... (0 Replies)
Discussion started by: ratheeshjulk
0 Replies

7. Shell Programming and Scripting

Find and replace a word in all the files (that contain the word) under a directory

Hi Everyone, I am looking for a simple way for replacing all the files under a directory that use the server "xsgd1234dap" with "xsdr3423pap". For Example: In the Directory, $pwd /home/nick $ grep -l "xsgd1234dap" *.sh | wc -l 119 I have "119" files that are still using... (5 Replies)
Discussion started by: filter
5 Replies

8. Shell Programming and Scripting

Replace a word in a string starting with another word

Hi All, I have a file in which a number of lines are starting with similar first word but different next words. I want to replace the any nth word(not 1st or 2nd) with another word. Eg:- My file contains are like this:- Ram is a boy. Ram is a good boy. Ram plays cricket. Here I want to... (2 Replies)
Discussion started by: mukeshbaranwal
2 Replies

9. Shell Programming and Scripting

Replace a word after a particular word in a file

Hi, I want to replace a word in a file which occurs after a particular word. For example : $cat file.txt CASE WHEN AND c1 = 'I' AND c2= '2' THEN 1 WHEN AND c1= 'I' AND c2= '0' THEN 2 So in this example i want to replace... (4 Replies)
Discussion started by: ashwin3086
4 Replies

10. Shell Programming and Scripting

Problem with awk while handling special charaters

Hi, I have an application.xml file like </dependency> <artifactId>_AdminServicesEAR</artifactId> <version>1.0.0-20080521.085352-1</version> <context-root>oldvalue</context-root> <type>ear</type> <DOCTYPE "abc/xyz/eft"> <NewTag>value123</xyz> ... (4 Replies)
Discussion started by: subin_bala
4 Replies
Login or Register to Ask a Question