return a string from a file

Microsoft Windows xp home edition sp2b
July 27, 2009 at 10:13:32
Specs: Windows XP
Hi,

So i posted by mistake in the wrong forum.. sorry to double post...

I'm trying to automate a small batch file to find and return a specific string of characters within several folder within a sub folder...

here is my code so far

@echo off > collection.txt
for /f %%a in ('dir /ad /b /s') do (
for %%T in (%%a/_cards.dat) do (
find "id=" < %%T >> collection.txt))

the program is currently looking in the active folder in all subfolder then find all files named "_cards.dat" then find all line begining with "id=" and returning them... the result is a file named collection.txt that look more or less like the following:

id=1
id=2
id=3
id=4
etc...

So I would like to produce the same file but without having the "id=" in front of the id...

I try something like
set str=%%T
and
%str:~2%

but it does not want to work... So at the moment i use words to find and replace but it's pretty anoying since I need to produce this file quite offen

Any ideas ?


See More: return a string from a file

Report •


#1
July 27, 2009 at 17:23:26
@echo off & setLocal EnableDELAYedExpansion

set str=id=75
echo !str!
echo !str:~3!


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
July 28, 2009 at 01:49:24
Thanks a lot,

It really helped but I still got some difficulties

I modified my code to:

@echo off > collection.txt
setLocal EnableDELAYedExpansion
For /f %%a in ('dir /ad /b /s') do (
for %%T in (%%a/_cards.dat) do (
set str=%%T
find "id=" < !str! >> collection.txt))

does the same as my previous code

@echo off > collection.txt
setLocal EnableDELAYedExpansion
For /f %%a in ('dir /ad /b /s') do (
for %%T in (%%a/_cards.dat) do (
set str=%%T
find "id=" < !str:~3! >> collection.txt))

does not work what's wrong ?


Report •

#3
July 28, 2009 at 03:37:25
Hi,

I found an alternative solution that is doing exactly what I needed...

@echo off > collection.txt
setLocal EnableDELAYedExpansion
For /f %%a in ('dir /AD-H /B') do (
for %%T in (%%a/_cards.dat) do (
set str=%%T
find "id=" < !str! >> collection.txt
find "id=" < !str! >> collection.txt
find "id=" < !str! >> collection.txt
find "id=" < !str! >> collection.txt))
@echo off > collection.dat
for /f "tokens=* delims='id='" %%B in (collection.txt) do (
echo %%B >> collection.dat)
del collection.txt

thanks again


Report •

Related Solutions


Ask Question