Page 1 of 1
Removing quotes...
Posted: 26 Jul 2010 04:32
by miskox
I have a string:
Code: Select all
set tmpstring="String with ^^ character"
Question: how to remove quotes but ^^ should remain there. If I use %~ then one ^ gets removed.
Thanks,
Saso
Re: Removing quotes...
Posted: 26 Jul 2010 06:04
by aGerman
Not %~ removes the caret, but further commands.
Have a look at the example:
First I double the carets and call the subroutine. Now I echo %~1 and you will see all 4 carets.
But if you process it (e.g. using SET) you will lost the half in %x%. Now have a look what I did for %y%. SET
"varname=value
"Code: Select all
@echo off &setlocal
set tmpstring="String with ^^ character"
call :proc %tmpstring:^=^^%
pause
goto :eof
:proc
echo %~1
set x=%~1
echo %x%
set "y=%~1"
echo %y%
goto :eof
Regards
aGerman
Re: Removing quotes...
Posted: 30 Jul 2010 07:52
by miskox
Thanks, aGerman.
I used this:
This does exactly what I want.
Thanks again.
Saso
Re: Removing quotes...
Posted: 02 Aug 2010 16:47
by santhosh
hi agerman,
when i run this below code,in the output test file.. channeltransaction file name is add in the first row with the first row content.How to remove that.
FINDSTR /C:"AP", channelTransaction*.csv | FINDSTR /C:"C2S" > TEST.csv
i got output like
channelTransaction001.csv:APR10073100001400001
channelTransaction015.csv:APR10073119191200526
how to remove that word till :
kindly suggest.
Re: Removing quotes...
Posted: 02 Aug 2010 17:51
by aGerman
First: Your question is absolutely off topic in this thread. Open you own New Topic next time.
untested:
Code: Select all
>TEST.csv type nul
for /f "delims=: tokens=2" %%a in ('FINDSTR /C:"AP" channelTransaction*.csv ^| FINDSTR /C:"C2S"') do >>TEST.csv echo %%a
Regards
aGerman
Re: Removing quotes...
Posted: 02 Aug 2010 23:43
by santhosh
thanks german
i tried it but not working no file is created.
Re: Removing quotes...
Posted: 03 Aug 2010 03:31
by aGerman
At the moment you pipe one findstr output to the next findstr. That means AP
and C2S must be in the same line.
You could write
Code: Select all
>TEST.csv type nul
for /f "delims=: tokens=2" %%a in ('FINDSTR "AP C2S" channelTransaction*.csv') do >>TEST.csv echo %%a
In this case AC
or C2S must be found in a line that it would be written to the new file.
Regards
aGerman
Re: Removing quotes...
Posted: 03 Aug 2010 09:54
by santhosh
yes thanks agerman
now its working fine
Re: Removing quotes...
Posted: 04 Aug 2010 01:31
by santhosh
Dear agerman,
As u said is working fine,but if have many column till (say as 15 column)than wat can i do.
input file channel.csv
channelTransaction001.csv:APR10073100001400001,dd,gg,hh,jj,.......
channelTransaction015.csv:APR10073119191200526,gg,hh,yy,.............
Output like:
APR10073100001400001,dd,gg,hh,jj,.......
APR10073119191200526,gg,hh,yy,............
kindly help me as i am new to this.
Re: Removing quotes...
Posted: 04 Aug 2010 01:35
by santhosh
Kindly add this line to my previous post
No need to put FINDSTR .......just want to remove words before : in the first column remaining all should be printed.
Re: Removing quotes...
Posted: 04 Aug 2010 13:24
by aGerman
The colon and the filename before comes from findstr.
In case all last lines in your csv files are closed with a line break, you could simply use that:
Code: Select all
type channelTransaction*.csv>TEST.csv
Regards
aGerman
Re: Removing quotes...
Posted: 12 Aug 2010 01:50
by santhosh
hi agerman,
FINDSTR /C:"KA", channelTransaction*.csv | FINDSTR /C:"C2C" | FINDSTR /C:"TRANSFER" > test.csv
>TEST1.csv type nul
for /f "usebackq delims=: tokens=2*" %%a in ("test.csv") do >>TEST1.csv echo %%a,%%b
when i ran this script it spliting all the columns which contain :
but i want only first column
example -
input file channel.csv
channelTransaction001.csv:APR10073100001400001,dd:sgs,gg,hh,jj:tt,.......
channelTransaction015.csv:APR10073119191200526,gg:fhd,hh,yy:trry,.............
Output like:
APR10073100001400001,dd:sgs,gg,hh,jj:tt,.......
APR10073119191200526,gg:fhd,hh,yy:trry,............
Re: Removing quotes...
Posted: 12 Aug 2010 10:21
by aGerman
You could try it this way:
Code: Select all
for /f "usebackq delims=: tokens=2" %%a in ("test.csv") do (
for /f "delims=," %%b in ("%%a") do >>TEST1.csv echo %%b
)
Regards
aGerman