Search and Replace Quotes
Moderator: DosItHelp
Search and Replace Quotes
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
Thanks
Re: Search and Replace Quotes
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
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
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?
Thoughts?
Re: Search and Replace Quotes
Ok, but what do you try, that fails?
jeb
jeb
Re: Search and Replace Quotes
well... I have tried:
BatchSubstitute.bat " ' test.txt
BatchSubstitute.bat """ "" test.txt
BatchSubstitute.bat """ ' test.txt
BatchSubstitute.bat " ' test.txt
BatchSubstitute.bat """ "" test.txt
BatchSubstitute.bat """ ' test.txt
Re: Search and Replace Quotes
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
I see a bunch of strange characters. What is this?
Re: Search and Replace Quotes
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
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
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?
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
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.
jeb
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
Awesome. That works like a charm. Thanks SO much!
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: Search and Replace Quotes
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