Need your input here guys [updated]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
renzlo
Posts: 116
Joined: 03 May 2011 19:06

Need your input here guys [updated]

#1 Post by renzlo » 14 Oct 2011 02:39

Hi All,

I am struggling with this problem.

This is my source: http://www.mediafire.com/?b9n3bcqc8ky60dp

I 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
Last edited by renzlo on 14 Oct 2011 21:47, edited 1 time in total.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Need your input here guys

#2 Post by Ed Dyreen » 14 Oct 2011 11:54

'
You'll need to give a more precise example than just a download link,
I have no clue where to find this document string ??

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

Re: Need your input here guys

#3 Post by aGerman » 14 Oct 2011 12:57

renzlo wrote:Is there a way I can extract that value?

Value? Which of them? There are 422 Document-Numbers 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

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: Need your input here guys

#4 Post by renzlo » 14 Oct 2011 19:52

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

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

Re: Need your input here guys

#5 Post by aGerman » 15 Oct 2011 07:25

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 "..DTYS:" :?:

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]

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: Need your input here guys [updated]

#6 Post by renzlo » 15 Oct 2011 20:12

Many thanks aGerman, you're the best.

I learned a lot from you. You're a life saver. I'm really amazed.

Post Reply