Search and Replace Quotes

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dragonfly
Posts: 6
Joined: 19 Dec 2010 11:02

Search and Replace Quotes

#1 Post by dragonfly » 19 Dec 2010 13:45

Hi everyone... I have seen lots of posts out here with help for performing search and replace functionality in a batch program. BUT, I need to search and replace double quotes. Any thoughts on how to make that happen? Basically, I need to get rid of all double quotes in a file that I have.

Thanks

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Search and Replace Quotes

#2 Post by jeb » 19 Dec 2010 15:24

Hi dragonfly,

do you tested anything, or do you only think about it?
I can't see any problems in removing all quotes, with the standard batch syntax.

jeb

dragonfly
Posts: 6
Joined: 19 Dec 2010 11:02

Re: Search and Replace Quotes

#3 Post by dragonfly » 19 Dec 2010 16:38

Ok. Then, can you help me because it's not working for me. I want to replace all occurrences of a double quote with nothing (or, worst case, a single quote).

Thoughts?

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Search and Replace Quotes

#4 Post by jeb » 19 Dec 2010 16:46

Ok, but what do you try, that fails?

jeb

dragonfly
Posts: 6
Joined: 19 Dec 2010 11:02

Re: Search and Replace Quotes

#5 Post by dragonfly » 19 Dec 2010 17:05

well... I have tried:

BatchSubstitute.bat " ' test.txt
BatchSubstitute.bat """ "" test.txt
BatchSubstitute.bat """ ' test.txt

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Search and Replace Quotes

#6 Post by !k » 19 Dec 2010 17:33

dragonfly

Code: Select all

@echo off
:: Create the assembler program, by Herbert Kleebauer
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>  "%temp%.\sbs2.com"
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU!WvX0GwUY Wv;ovBX2Gv0ExGIuht6>> "%temp%.\sbs2.com"
echo ?@}IKuNWpe~Fpe?FNHlF?wGMECIQqo{Ox{T?kPv@jeoSeIlRFD@{AyEKj@>> "%temp%.\sbs2.com"
echo iqe~1NeAyR?mHAG~BGRgB{~H?o~TsdgCYqe?HR~upkpBG?~slJBCyA?@xA>> "%temp%.\sbs2.com"
echo LZp{xq`Cs?H[C_vHDyB?Hos@QslFA@wQ~~x}viH}`LYNBGyA?@xAB?sUq`>> "%temp%.\sbs2.com"
echo LRy@PwtCYQEuFK@A~BxPtDss@fFqjVmzD@qBEOEenU?`eHHeBCMs?FExep>> "%temp%.\sbs2.com"
echo LHsPBGyA?@xAunjzA}EKNs@CA?wQpQpKLBHv?s`WJ`LRCYyIWMJaejCksl>> "%temp%.\sbs2.com"
echo H[GyFGhHBwHZjjHeoFasuFUJeHeB?OsQH[xeHCPvqFj@oq@eNc?~}Nu??O>> "%temp%.\sbs2.com"
echo ~oEwoAjBKs?Zp`LBzHQzyEFrAWAG{EFrAqAGYwHTECIQ{coKIsaCsf{Oe~>> "%temp%.\sbs2.com"
echo CK}Ayre~CNFA{rAyEKFACrA{EKGAjbA}eKGSjNMtQFtc{OAyDGFj?{FDGQ>> "%temp%.\sbs2.com"
echo KAjNVk_OCAx@e?f{o?CosI}1EGizhljJ~H1ZeG}JBA~rACBMDGjjDG@g0>>  "%temp%.\sbs2.com"
:: Use the program
:: Файлы начальный и конечный должны быть РАЗНЫЕ.
:: Путь хоть какой ОБЯЗАТЕЛЬНО в кавычки.
:: А если редактировать фаил там же, где и батник, то пути писать не надо
rem "%temp%.\sbs2.com" 0 "Old String" "New String" < "infile" > "outfile"
"%temp%.\sbs2.com" 0 "$22" "$27" < "c:\in\test.txt" > "d:\out\test'.txt"
:: Delete the program
del "%temp%.\sbs2.com"

dragonfly
Posts: 6
Joined: 19 Dec 2010 11:02

Re: Search and Replace Quotes

#7 Post by dragonfly » 19 Dec 2010 21:38

I see a bunch of strange characters. What is this?

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Search and Replace Quotes

#8 Post by jeb » 20 Dec 2010 03:58

Ok, if you use the standard BatchSubstitute you can not replace single quotes,
because it is not possible to create a cmd-line-parameter with a single quote.

But you can use the improved Batchsubstitute http://www.dostips.com/forum/viewtopic.php?f=3&t=1516&p=5713

And use
BatchSubstitute.bat """" "" test.txt

hope it helps
jeb

dragonfly
Posts: 6
Joined: 19 Dec 2010 11:02

Re: Search and Replace Quotes

#9 Post by dragonfly » 20 Dec 2010 04:53

Ok. That works GREAT except...

Here is my test file:

19"
19 feet
20"TV

The output I get is:
19
19 feet

Any thoughts on why I lose the last line?

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Search and Replace Quotes

#10 Post by jeb » 20 Dec 2010 05:43

Yes, findstr fails, because the last line have no line end.

you could replace the $ with ^^ in findstr, so it also finds the last line of a file.

Code: Select all

for /f "delims=" %%A in ('"findstr /n ^^ %3"') do (


jeb

dragonfly
Posts: 6
Joined: 19 Dec 2010 11:02

Re: Search and Replace Quotes

#11 Post by dragonfly » 20 Dec 2010 07:21

Awesome. That works like a charm. Thanks SO much!

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: Search and Replace Quotes

#12 Post by ghostmachine4 » 26 Dec 2010 19:35

dragonfly wrote:Hi everyone... I have seen lots of posts out here with help for performing search and replace functionality in a batch program. BUT, I need to search and replace double quotes. Any thoughts on how to make that happen? Basically, I need to get rid of all double quotes in a file that I have.

Thanks


Use a tool specialized for the job , not batch. If you can download stuff, you can try sed for windows

Code: Select all

C:\test>more file
19"
19 feet
20"TV

C:\test>sed "s/\"//g" file
19
19 feet
20TV



Just one line does the job

Post Reply