batch file to remove characters in a txt file

April 19, 2010 at 13:12:04
Specs: Windows XP
Hey guys,

I've seen lots of postings on this subject, but none that matches my requirement. So:

I have a text file where lines look like this one:

E1532 C1010 A0000 52112 10 89332.182 80687.132 89332.182 86450.499

I would need a batch script (Windows XP) that removes the letters and leaves only the numerical characters. String are "tab" delimited, so I would like for the "tabs" to still remain in there (later import in another application).

Given that the file has thousands of lines, and that I can only use batch scripting, any help would be greately apreciated.

Thanks a lot.


See More: batch file to remove characters in a txt file

Report •


#1
April 19, 2010 at 13:37:46
Are the letters always in cols 1, 7 &13?

oops
... your tabs got trashed.

Are the letters always in the same columns?

Does the line look like this?

E1532	C1010	A0000	52112	10	89332.182	80687.132	89332.182	86450.499


=====================================
Helping others achieve escape felicity

M2


Report •

#2
April 19, 2010 at 14:05:17
Those letters are Hex do you want them to be converted to decimal?

Report •

#3
April 20, 2010 at 05:45:14
Thanks for the quick reply.

Mechanix:

The letters are always in the same columns. The problem is that out of 6000 lines, about 1000 have these letters in the filed, while the rest don't. This is why I think a deletion based on position will not work.
Entity CostC Activity Account ......
E1532 C1010 A0000 52112 .....
1533 1011 0001 52112 .........

Ace: not sure I understand your question. I do not want E, C and A converted, just to have all of them removed, so that I can upload the numerical fields into an Application.

Thanks.


Report •

Related Solutions

#4
April 20, 2010 at 16:35:26
downloadsed for windows, and then do this

c:\test>  sed -i.bak  "s/[a-zA-Z]//g" file
1532 1010 0000 52112 10 89332.182 80687.132 89332.182 86450.499

GNU win32 packages | Gawk


Report •

#5
April 21, 2010 at 08:13:54
Hey guys,

I ended up running this script 3 times (one for each letter). Not ideal, since it triples my processing time, but does the job.

I would still appreciate if you find a better solution.

Thanks.

@echo off
if "%1"=="GoTo" goto %2
%comspec% /v:on /c %0 GoTo start
goto:eof
:start
type nul> %temp%.\$
for /F "tokens=*" %%S in (merge.txt) do (
set str=%%S
echo !str:E=!>> %temp%.\$
)
copy/y %temp%.\$ merge.txt > nul
del %temp%.\$


Report •

#6
April 21, 2010 at 10:34:43
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (myfile.txt) do (
set S=%%a
set S=!S:A=!
set S=!S:C=!
set S=!S:E=!
>> newfile echo.!S!
)


=====================================
Helping others achieve escape felicity

M2


Report •

#7
April 21, 2010 at 12:18:29
Thanks a lot Mechanix.

Works like a charm.


Report •


Ask Question