Convert .txt file to .csv file with single quotations

Hi All,

I'm using the following .bat file to convert a .txt file to a .csv file

@echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%a in ('type "%~1"') do (
   set line=%%a
   echo "!line:|=","!">>"%~2"
)

Open in new window


However my output file is coming out like this
"999859","0000000000000000000000000","PATIENT NOT FOUND"
"999380","0000000000000000000000000","PATIENT NOT FOUND"

Open in new window


When i need it to be like this, essentially replacing the surrounding double quotes with single quotes.
'999859','0000000000000000000000000','PATIENT NOT FOUND'
'999380','0000000000000000000000000','PATIENT NOT FOUND'

Open in new window


Is there any way to modify the .bat file script to accomplish this? Possibly doing a find and replace on the output file?

Thanks for the assistance!
robthomas09Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Just change the script to use single quotes instead of double quotes:
@echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%a in ('type "%~1"') do (
   set line=%%a
   echo '!line:|=','!'>>"%~2"
)

Open in new window

0
robthomas09Author Commented:
I get the following error when i try to run the .bat file from a cmd prompt

C:\Users\djl4616\Desktop>CONVERT test.txt test.csv
''' is not recognized as an internal or external command,
operable program or batch file.

Open in new window


It still creates an output (test.csv) file but it is blank
0
oBdACommented:
Sorry, missing caret:
@echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%a in ('type "%~1"') do (
   set line=%%a
   echo '!line:^|=','!'>>"%~2"
)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robthomas09Author Commented:
That worked beautifully! Thank You!
0
Bill PrewCommented:
Since you know there will be three fields, a slightly simpler approach could be:

@echo off
for /f "tokens=1-3 delims=|" %%a in ('type "%~1"') do echo '%%~a','%%~b','%%~c'>>"%~2"

Open in new window

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.