0

I got a list in text file (names.txt) like this:

This is documment no....... etc

Sent : 20.04.2013

Details for ............. etc

Num : 1

Name : John

Surname : White

Born : 09/17/1993

Num : 2

Name : Peter

Surname : Tosh

Born : 09/14/1991

............. .............

This documment can not............

@echo off 

setlocal enabledelayedexpansion

for /F "delims=" %%a in (C:\tmp\names.txt) do (
    set /A count1+=1
    set "array!count1!=%%a"
)
set /A count1-=1

set /A count2=1
set /A count3=2

for /L %%i in (4,4,%count1%) do (
    set /A count2+=4
    set /A count3+=4
    echo !array%%i!  !array%count2%!  !array%count3%!
)

I want to list them like

Num : 1 Name :John Surname : White

Num : 2 Name :Peter Surname : Tosh

Num : 3 Name :Me Surname : Myself

..............

Just 3 data in one row but doesnt work. What I'm doing wrong?

3 Answers 3

1

The Batch file below solve the problem as stated; it does not require any array:

@echo off
setlocal EnableDelayedExpansion

set "Surname="
for /F "tokens=1,2 delims=: " %%a in (C:\tmp\names.txt) do (
   set "%%a=%%b"
   if defined Surname (
      echo Num : !Num! Name : !Name! Surname : !Surname!
      set "Surname="
   )
)

Output:

Num : 1 Name : John Surname : White
Num : 2 Name : Peter Surname : Tosh
Sign up to request clarification or add additional context in comments.

Comments

0

Test this to see if it does what you need:

@echo off 
for /F "usebackq delims=" %%a in ("C:\tmp\names.txt") do (
  set /p "=%%a "<nul
  echo "%%a" |find /i "Born" >nul && echo(
)
pause

Comments

0

How about this:

echo off
setlocal enabledelayedexpansion

set xSurname=
for /f "tokens=1,2 delims=: " %%a in (%TEMP%\names.txt) do (
    if /i '%%a'=='Num' set xNum=%%b
    if /i '%%a'=='Name' set xName=%%b
    if /i '%%a'=='Surname' set xSurname=%%b
    if not '!xSurname!'=='' (
        echo Num: !xNum! Name: !xName! Surname: !xSurname!
        set xSurname=
    )
)

Makes assumptions that the Surname line ends a block (Born: is ignored) and outputs what it has gathered to that point in the block. Note I changed the path to %TEMP% vs C:\tmp. You probably would do better using %TEMP% as that's set by the operating system.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.