Removing quotes...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Removing quotes...

#1 Post by miskox » 26 Jul 2010 04:32

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Removing quotes...

#2 Post by aGerman » 26 Jul 2010 06:04

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

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: Removing quotes...

#3 Post by miskox » 30 Jul 2010 07:52

Thanks, aGerman.

I used this:

Code: Select all

set "y=%~1"


This does exactly what I want.

Thanks again.
Saso

santhosh
Posts: 41
Joined: 02 Aug 2010 05:10

Re: Removing quotes...

#4 Post by santhosh » 02 Aug 2010 16:47

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Removing quotes...

#5 Post by aGerman » 02 Aug 2010 17:51

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

santhosh
Posts: 41
Joined: 02 Aug 2010 05:10

Re: Removing quotes...

#6 Post by santhosh » 02 Aug 2010 23:43

thanks german

i tried it but not working no file is created.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Removing quotes...

#7 Post by aGerman » 03 Aug 2010 03:31

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

santhosh
Posts: 41
Joined: 02 Aug 2010 05:10

Re: Removing quotes...

#8 Post by santhosh » 03 Aug 2010 09:54

yes thanks agerman
now its working fine

santhosh
Posts: 41
Joined: 02 Aug 2010 05:10

Re: Removing quotes...

#9 Post by santhosh » 04 Aug 2010 01:31

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.

santhosh
Posts: 41
Joined: 02 Aug 2010 05:10

Re: Removing quotes...

#10 Post by santhosh » 04 Aug 2010 01:35

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Removing quotes...

#11 Post by aGerman » 04 Aug 2010 13:24

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

santhosh
Posts: 41
Joined: 02 Aug 2010 05:10

Re: Removing quotes...

#12 Post by santhosh » 12 Aug 2010 01:50

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,............

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Removing quotes...

#13 Post by aGerman » 12 Aug 2010 10:21

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

Post Reply