How do I escape double quotes from WITHIN double quotes?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
autoamerican
Posts: 10
Joined: 02 Jul 2012 13:23

How do I escape double quotes from WITHIN double quotes?

#1 Post by autoamerican » 04 Oct 2012 12:01

I'm throwing together a quick one-line batch to run a command on one of my servers and dump the output to a text file. I have to tokenize the output, and unfortunately the output contains quotation marks.

Here's a sample of the output:

Type Name Status Version
--------------------------------------------------------------------
le "OvSvcDiscErrorLog" enabled 0011.0000
le "OvSvcDiscServerLog" enabled 0011.0000
msgi "MS Win Catch All opcmsg" enabled 0001.0044
msgi "Magic Integration Test" enabled 0001.0008


The only stuff I want is the stuff under the Name column, including the quotation marks (I'll need them later). You can see that some of my lines have spaces between the quotes, so I can't just tokenize it on a space or I lose half of my wording.

Here's how I'm trying to escape the quotes, but no luck:

Code: Select all

for /f "delims=^"" %%p in ('ovpolicy -list -level 0') do echo %%p >> c:\policies.txt

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How do I escape double quotes from WITHIN double quotes?

#2 Post by Squashman » 04 Oct 2012 12:20

try this

Code: Select all

for /f delims^=^" %%p in ('ovpolicy -list -level 0') do echo %%p >> c:\policies.txt

aGerman
Expert
Posts: 4742
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How do I escape double quotes from WITHIN double quotes?

#3 Post by aGerman » 04 Oct 2012 12:26

Actually I don't understand why you have to tokenize it. How should the output look like?

Regards
aGerman

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How do I escape double quotes from WITHIN double quotes?

#4 Post by Squashman » 05 Oct 2012 08:34

Realized I forgot the tokens.

Code: Select all

for /f tokens^=2^ delims^=^" %%p in (file.txt) do echo "%%p"

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: How do I escape double quotes from WITHIN double quotes?

#5 Post by abc0502 » 05 Oct 2012 08:50

Squashman wrote:Realized I forgot the tokens.

Code: Select all

for /f tokens^=2^ delims^=^" %%p in (file.txt) do echo "%%p"


Do you mind explaining that ?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How do I escape double quotes from WITHIN double quotes?

#6 Post by Squashman » 05 Oct 2012 09:00

abc0502 wrote:
Squashman wrote:Realized I forgot the tokens.

Code: Select all

for /f tokens^=2^ delims^=^" %%p in (file.txt) do echo "%%p"


Do you mind explaining that ?

Wait for Jeb. I learned that from him.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: How do I escape double quotes from WITHIN double quotes?

#7 Post by Ed Dyreen » 07 Oct 2012 14:45

Code: Select all

for /f tokens^=1-3^ delims^=^" %a in ("aaa"bbb ccc"") do echo.%a,%b,%c_
sets " as delimiter

Code: Select all

aaa,bbb ccc,_
http://www.dostips.com/forum/viewtopic.php?p=18886#p18886

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: How do I escape double quotes from WITHIN double quotes?

#8 Post by abc0502 » 07 Oct 2012 15:06

Ed Dyreen wrote:

Code: Select all

for /f tokens^=1-3^ delims^=^" %a in ("aaa"bbb ccc"") do echo.%a,%b,%c_
sets " as delimiter

Code: Select all

aaa,bbb ccc,_
http://www.dostips.com/forum/viewtopic.php?p=18886#p18886


Thanks Ed Dyreen i was searching for the topic of this method :D

Post Reply