Page 1 of 1

Search and Replace Quotes

Posted: 19 Dec 2010 13:45
by dragonfly
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

Re: Search and Replace Quotes

Posted: 19 Dec 2010 15:24
by jeb
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

Re: Search and Replace Quotes

Posted: 19 Dec 2010 16:38
by dragonfly
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?

Re: Search and Replace Quotes

Posted: 19 Dec 2010 16:46
by jeb
Ok, but what do you try, that fails?

jeb

Re: Search and Replace Quotes

Posted: 19 Dec 2010 17:05
by dragonfly
well... I have tried:

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

Re: Search and Replace Quotes

Posted: 19 Dec 2010 17:33
by !k
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"

Re: Search and Replace Quotes

Posted: 19 Dec 2010 21:38
by dragonfly
I see a bunch of strange characters. What is this?

Re: Search and Replace Quotes

Posted: 20 Dec 2010 03:58
by jeb
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

Re: Search and Replace Quotes

Posted: 20 Dec 2010 04:53
by dragonfly
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?

Re: Search and Replace Quotes

Posted: 20 Dec 2010 05:43
by jeb
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

Re: Search and Replace Quotes

Posted: 20 Dec 2010 07:21
by dragonfly
Awesome. That works like a charm. Thanks SO much!

Re: Search and Replace Quotes

Posted: 26 Dec 2010 19:35
by ghostmachine4
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