Page 1 of 1
Need your input here guys [updated]
Posted: 14 Oct 2011 02:39
by renzlo
Hi All,
I am struggling with this problem.
This is my source:
http://www.mediafire.com/?b9n3bcqc8ky60dpI want to find this string: "..Document-Number:" and it's value.
The problem is the value is on the next line of the found string.
Is there a way I can extract that value?
Kindly help me. Thanks in advance.
-renzlo
Re: Need your input here guys
Posted: 14 Oct 2011 11:54
by Ed Dyreen
'
You'll need to give a more precise example than just a download link,
I have no clue where to find this document string ??
Re: Need your input here guys
Posted: 14 Oct 2011 12:57
by aGerman
renzlo wrote:Is there a way I can extract that value?
Value? Which of them? There are 422 Document-Number
s in your file.
Code: Select all
@echo off &setlocal enabledelayedexpansion
set /a found=0
for /f "usebackq tokens=* delims=" %%i in ("SCOL000016_ln.br3") do (
if !found!==1 (
echo %%i
set /a found=0
)
if "%%i"=="..Document-Number:" set /a found=1
)
pause
Regards
aGerman
Re: Need your input here guys
Posted: 14 Oct 2011 19:52
by renzlo
@ed
I'm sorry for not being clear.
@aGerman
Thank you so much. This is exactly what I want, would you mind explaining that to me? I'm amazed.
Additional tasks, I need to do this also to string "..DTYG:" and "..DTYG:" and save the output in 3 Columns (CSV), can it be done?
Many thanks aGerman.
Re: Need your input here guys
Posted: 15 Oct 2011 07:25
by aGerman
renzlo wrote:would you mind explaining that to me?
It's simple. Since the value is always in the next line I search for "..Document-Number:" and if it was found I set the value of variable
found to 1. Now it iterates to the next line. Because
found is 1 this line will be outputted. At the same time I set
found back to 0.
Now it iterates across the next lines until "..Document-Number:" will be found again etc.
renzlo wrote:I need to do this also to string "..DTYG:" and "..DTYG:"

"..DTYG:" and "..DTY
S:"
renzlo wrote:save the output in 3 Columns (CSV), can it be done?
Of course, but these 3 values have to exist in each block and they must be always in the same order
Code: Select all
@echo off &setlocal enabledelayedexpansion
set "source=SCOL000016_ln.br3"
set "dest=test.csv"
set "separator=,"
>"%dest%" type nul
set /a found1=0, found2=0, found3=0
for /f "usebackq tokens=* delims=" %%i in ("%source%") do (
if !found1!==1 (
set "out=%%i"
set /a found1=0
)
if !found2!==1 (
set "out=!out!%separator%%%i"
set /a found2=0
)
if !found3!==1 (
>>"%dest%" echo !out!%separator%%%i
set /a found3=0
set "out="
)
if "%%i"=="..Document-Number:" set /a found1=1
if "%%i"=="..DTYG:" set /a found2=1
if "%%i"=="..DTYS:" set /a found3=1
)
Regards
aGerman
[EDIT] It worked before (for some reason), but I replaced line
set /a found=0 with
set /a found1=0, found2=0, found3=0 to make sure the IF statements won't fail in the beginning. [/EDIT]
Re: Need your input here guys [updated]
Posted: 15 Oct 2011 20:12
by renzlo
Many thanks aGerman, you're the best.
I learned a lot from you. You're a life saver. I'm really amazed.