sed replacing quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed replacing quotes
# 1  
Old 04-06-2012
sed replacing quotes

Hi!

I'd like to ask for help with the following problem: Using sed all double quotes (") in a textfile should be replaced with two of them ("") but not - and here is my problem - if two are already present ("")...

For example:
"this is an ""sample"" text"

should be
""this is an ""sample"" text""

Thanks for reading and help!
Reinhard
# 2  
Old 04-06-2012
sed

Hi,

Try this one,

Code:
echo "\"this \"\"\"is an \"\"sample\"\" text\"" | sed 's/""/#/g;s/"/""/g;s/#/""/g'

Cheers,
RangaSmilie
# 3  
Old 04-06-2012
Perl, ok?

Code:
$ cat inputfile
"this is an ""sample"" text"
"this is an ""sample"" text"
$
$ perl -pe 's/(?<!\")\"(?!\")/""/g' inputfile
""this is an ""sample"" text""
""this is an ""sample"" text""
$

# 4  
Old 04-06-2012
Bug

Code:
echo \"this is an \"\"sample\"\" text\"  |  sed 's/\"/\""/g'


Smilie

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 04-06-2012 at 07:15 AM..
# 5  
Old 04-06-2012
Thank you for your replies. The following code from Ranga's suggestion solved this problem.

Code:
echo "\"this \"\"is an \"\"sample\"\" text\"" | sed 's/""/#/g;s/"/""/g;s/#/""/g'

Have a nice weekend!
Reinhard
# 6  
Old 04-06-2012
Code:
sed -r 's#"{2}#|#g;s#"|\|#""#g' infile

# 7  
Old 04-06-2012
Code:
sed 's/""*/""/g' infile

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed and double quotes

I am working on a Raspberry Pi and using sed to update the SSID and password but the config file requires the SSID and PSK to both be in double quotes. Below is the code I am using but I cannot figure out how to include the double quotes. script: #!/bin/bash read -p "Please specify the... (2 Replies)
Discussion started by: NickCostas
2 Replies

2. Shell Programming and Scripting

Removing quotes in sed

I have a file and I want to remove quotes from the word " ` " through sed command but unable to remove I am using below command sed s/"`XYZ`"/"ZXY"/g file1.txt > file2.txt But this is not working. How can we remove "`" through sed command (2 Replies)
Discussion started by: kaushik02018
2 Replies

3. Shell Programming and Scripting

Replacing double quotes with the unicodes "urgent!"

Hi, I have the following text in a file <div class="snippet abstract"> We present a new "model" for multiple-input-multiple-output (MIMO) 'outdoor' has many things "what" ever </div></a href=sdfkkf"> </div> <div class="snippet context"> I have to replace the string between the <div... (1 Reply)
Discussion started by: vms
1 Replies

4. Shell Programming and Scripting

sed inside sed for replacing string

My need is : Want to change docBase="/something/something/something" to docBase="/only/this/path/for/all/files" I have some (about 250 files)xml files. In FileOne it contains <Context path="/PPP" displayName="PPP" docBase="/home/me/documents" reloadable="true" crossContext="true">... (1 Reply)
Discussion started by: linuxadmin
1 Replies

5. Shell Programming and Scripting

Replacing comma with in double quotes in a csv file

Hello, I need to read a csv file and I am trying to replace a comma with a text DSEE?DSEE. Example Input "Chapter","NewTrains, "oldTrains","Delayed",10,"London" "Chapter","Newbuses,oldbuses","On Time",20,"London" Output "Chapter","NewTrainsDSEE?DSEE... (5 Replies)
Discussion started by: venkatvani
5 Replies

6. UNIX for Dummies Questions & Answers

Need help replacing quotes

Hello, I have an array as an output that looks similar to this: Is it possible to remove all of the single quotes from the integers and leave them on the operators so that the output would be: Any help would be appreciated. (12 Replies)
Discussion started by: jl487
12 Replies

7. Shell Programming and Scripting

sed strange quotes behavior

Hi gurus input file: 1 2 3 4 desired output 1 2\ 2a 3 4 I tried (6 Replies)
Discussion started by: wakatana
6 Replies

8. Shell Programming and Scripting

sed and double quotes

I have not seen anything yet in your forum to answer this problem. Here is my sed command. I want to change Build Apache module" off to Build Apache module" on This is what I am trying. sed "s_Build Apache module\" off_Build Apache module\" on_" /usr/ports/lang/php5/Makefile... (9 Replies)
Discussion started by: triumdh
9 Replies

9. Shell Programming and Scripting

Use variables with double quotes sed -i

I have the following line of code: sed -i "/MatchText/ s/${tgrepLine}/${tNewLine}/" filename.outputfilename.output contains this: blablabla PATH=".:/home/root/bin/:/usr/local/bin/" blablablaVariable ${tgrepLine} contains: PATH=".:/home/root/bin/:/usr/local/bin/" Variable ${tNewLine}... (3 Replies)
Discussion started by: inspire87
3 Replies

10. UNIX for Dummies Questions & Answers

Using sed to substitute between quotes.

I'm using sed to perform a simply search and replace. The typical data is: <fig><image href="Graphics/BAV.gif" align="left" placement="break" I need to replace the value in the first set of quotes, keeping the remainder of the line the same. Thus: <fig><image href="NEW_VALUE" align="left"... (3 Replies)
Discussion started by: Steve_altius
3 Replies
Login or Register to Ask a Question