LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-11-2020, 05:51 PM   #1
walterbyrd
Member
 
Registered: Apr 2004
Posts: 734

Rep: Reputation: 46
vim cannot replace double quotes


Code:
<p>This privacy policy (“policy”) will help you understand how thissite.com (“us”, “we”, “our”) uses and protects the data you provide to us when you visit and use thissite.com (“website”, “service”).</p>
HTML needs the " replaced with &quot; so I have tried:

Code:
:%s/\"/&quot;/g
and

Code:
:%s/"/&quot;/g
But I keep getting the error:
Code:
E486: Pattern not found: \"
or
Code:
E486: Pattern not found "
Why can it not find the pattern?

Last edited by walterbyrd; 09-11-2020 at 05:55 PM.
 
Old 09-11-2020, 06:25 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Leave out the backslash, and add it before the &:
Code:
s/"/\&quot;/g
The ampersand has a special meaning (the text that matches the search pattern) and must be escaped.
 
Old 09-12-2020, 09:24 AM   #3
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,643

Rep: Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561Reputation: 2561
Quote:
Originally Posted by walterbyrd View Post
HTML needs the " replaced with &quot;
No it does not!

If a tag's attribute starts with a double quote, then double quotes within the attribute's value need to be escaped (so they are not misinterpreted as the end of the value), but that is the only situation it needs doing.

(Of course, there is a difference between ASCII double quote (") and the angled quotes in your string - you may or not want &ldquo; and &rdquo; instead.)


Last edited by boughtonp; 09-12-2020 at 09:29 AM.
 
Old 09-15-2020, 06:47 AM   #4
walterbyrd
Member
 
Registered: Apr 2004
Posts: 734

Original Poster
Rep: Reputation: 46
Code:
:s/"/\&quot;/g
Did not work either. Not with string that I used in my original post. I got the same answer.

> (Of course, there is a difference between ASCII double quote (") and the angled quotes in your string - you may or not want &ldquo; and &rdquo; instead.)

THAT was the issue. It did not occur to me that those were not ASCII double quotes.

Went back and copy pasted those angel quotes, and it worked.

Code:
:s/”/\&quot;/g 
:s/“/\&quot;/g

Last edited by walterbyrd; 09-15-2020 at 06:56 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Difference between echo of file within double quotes and without double quotes ankitpandey Programming 2 01-11-2013 09:02 AM
translate value from single quotes to double quotes venkateshrupineni Linux - Newbie 2 06-14-2012 03:03 PM
Double Quotes Inside Double Quotes youarefunny Programming 6 06-09-2010 10:21 PM
Problems with quotes and double quotes Andruha Slackware 6 01-02-2010 04:44 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration