Solved Replace ' with no spacing in csv file in 1st column

July 13, 2012 at 21:06:21
Specs: WinXP,Win7,WinNT
Hi,

Can someone help me write a batch file to replace ' to no spacing.

example csv file
column1,column2
can't,I want to make it work but I can't
can,yes you can do it

change to
cant,I want to make it work but I can't
can,yes you can do it

replace only the first column ' to no spacing for all the csv file in the folder.

I try to do this using fart command, but I can't seems to replace ' with no spacing. I can only replace ' with a space and the worst is, it is replacing the whole csv file and not the first columm.

@ECHO OFF
CLS
TYPE Test_01.csv >> Test_03.csv
fart -C Test_03.csv "'" " "
pause
END

Thank you.


See More: Replace with no spacing in csv file in 1st column

Report •


✔ Best Answer
July 14, 2012 at 23:34:29
I spose if the requirement stated dblq removal we needn't have gone through all these gyrations.


=====================================
Life is too important to be taken seriously.

M2



#1
July 13, 2012 at 21:55:12
@echo off > newfile.csv & setlocal enabledelayedexpansion
for /f "tokens=1* delims=," %%a in (sample.csv) do (
set x=%%a
set x=!x:'=!
set y=%%b
if defined y set y=,!y!
>>newfile.csv echo !x!!y!
)

Report •

#2
July 13, 2012 at 21:57:05
:: ===== script starts here ===============
::
:: jeremy.bat 2012-07-14 11:42:53.89
@echo off > newfile & setLocal enableDELAYedeXpansioN

for /f "tokens=1* delims=," %%a in (my.csv) do (
call :sub1 %%a
echo !C!, %%b >> newfile
)
goto :eof

:sub1
set C=%*
set C=!C:'=!

goto :eof

::====== script ends here =================


=====================================
Life is too important to be taken seriously.

M2


Report •

#3
July 13, 2012 at 22:01:26
hi nbrane,

I think I got subs on the brain today.


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
July 14, 2012 at 00:26:17
Hi Mechanix2Go and nbrane,

Thank you so much.

This batch file can replace the (') for

Men's to Mens
and
Women's to Womens

However it cannot replace
10' Coil, 2 1/4"h X 5/8"w
and
4.5'' X 16''


I Change the batch file to the u/m because the sub that Mechanix2Go wrote give me error.

@echo off
setlocal enabledelayedexpansion

for /f "tokens=* delims= " %%A in ('dir /b *.csv') do (
set NAME=%%~nA
call :sub1 %%A
)
goto :eof

:sub1

for /f "tokens=1* delims=," %%a in (%*) do (
set x=%%a
set x=!x:'=!
set y=%%b
if defined y set y=,!y!
>>!NAME!.txt echo !x!!y!
)


Report •

#5
July 14, 2012 at 00:59:45
Works here. Newfile:

column1, column2
cant, I want to make it work but I can't
can, yes you can do it
10 Coil, 2 1/4"h X 5/8"w
4.5 X 16,


=====================================
Life is too important to be taken seriously.

M2


Report •

#6
July 14, 2012 at 01:06:05
Strange how come my computer cannot.

Im using WinXP and Win7. Try on both computer, doesn't work.

What can be the reason?


Report •

#7
July 14, 2012 at 01:59:07
What is the EXACT name of your bat file?


=====================================
Life is too important to be taken seriously.

M2


Report •

#8
July 14, 2012 at 08:20:26
Change.bat is the exect name.

Report •

#9
July 14, 2012 at 10:36:52
Hi M2go: coffee time right now...

Works here, but I had to add this line:
set x=!x:"=!

(right after the line: set x=!x:'=!)
to get rid of the dbl-quote.

i just called my testbatch "xx.bat", and it same as last posted script except for the addition of the above-described line. might want to add this line in the main body:
echo off>!NAME!.txt
to erase previous runs outputs.


Report •

#10
July 14, 2012 at 22:58:41
Hi nbrane and Mechanix2Go,

I got it working after adding
set x=!x:"=!

Adding this line not only get rid of the dbl-quote but also
the (') for the
10' Coil, 2 1/4"h X 5/8"w
and
4.5'' X 16''

Nice.

Thank you so much.
Jeremy


Report •

#11
July 14, 2012 at 23:34:29
✔ Best Answer
I spose if the requirement stated dblq removal we needn't have gone through all these gyrations.


=====================================
Life is too important to be taken seriously.

M2


Report •


Ask Question