This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
34} How can I remove the quote characters from a line?
Below is a demonstration
@echo off & setlocal enableextensions
::
:: Set up a test
set line_="54321","1","3","1234567890122","","","","","",""
echo %line_%
::
:: Omit the quotes
set line_=%line_:"=%
::
:: List the first four fields
for /f "tokens=1-4 delims=," %%f in ('echo %line_%') do (
call :ListThem %%f %%g %%h %%i)
endlocal & goto :EOF
:: ======================================================
:ListThem
setlocal enableextensions
echo.%1
echo.%2
echo.%3
echo.%4
endlocal & goto :EOF
The output will be
D:\TEST>batfaq
"54321","1","1","1234567890122","","","","","",""
54321
1
3
1234567890122
Using
SED
@echo off & setlocal enableextensions
::
:: Set up a test
set line_="54321","1","3","1234567890122","","","","","",""
echo %line_%
echo %line_%|sed -e "s/\x22//g"
for /f "tokens=* delims=" %%a in (
'echo %line_%^|sed -e "s/
\x22//g"') do set lineNQ=%%a
echo %lineNQ%
endlocal & goto :EOF
The output is
C:\_D\TEST>cmdfaq
"54321","1","3","1234567890122","","","","","",""
54321,1,3,1234567890122,,,,,,
54321 1 3 1234567890122
1) Note the different outcomes. In FOR /F the commas (,) count as default
delimiters.
2) \x22 is hex for "
@echo off & setlocal enableextensions
rem C:\_M\TEST\CMDTEST.CMD
::
:: Set up a test
set line_="54321","1","3","1234567890122","","","","","",""
echo %line_%
::
:: Build a Visual Basic Script
set skip=
set vbs_=%temp%\tmp$$$.vbs
>"%vbs_%" findstr "'%skip%VBS" "%~f0"
::
:: Run it with Microsoft Windows Script Host Version 5.6
for /f "tokens=* delims=" %%a in ('
echo %line_%^|cscript //nologo "%vbs_%"') do (
set lineNQ=%%a)
::
:: Clean up
for %%f in ("%vbs_%") do if exist %%f del %%f
::
:: Display the result
echo %lineNQ%
endlocal & goto :EOF
'
'............................................
'The Visual Basic Script
'
Do While Not WScript.StdIn.AtEndOfStream 'VBS
str = WScript.StdIn.ReadLine 'VBS
str = Replace (str, Chr(34),"") 'VBS
WScript.StdOut.WriteLine str 'VBS
Loop 'VBS
C:\_M\TEST>cmdtest
"54321","1","3","1234567890122","","","","","",""
54321 1 3 1234567890122