Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
From a batch file how do I parse a text file (say c:\text.txt) that looks like this.....
User: LINLXB01
Full Name: LORRAINE K. BUCKWALD
User: LIN765
Full Name: 765 print server
User: LINPDN01
Full Name: Patrick D Nespor.......into delimited text file like this?
LINLXB01~LORRAINE K. BUCKWALD
LIN765~765 print server
LINPDN01~Patrick D NesporThanks

The script you find fits your task, but it works under Win NT/2K/XP only and the input file must hold the format you posted.
I named it TParse.bat and the command line looks
TParse File_In File_Out
No blanks allowed in Filenames.
I tested under XP/2K and worked fine, but if you get any trouble, post again.
Warening: no CR/LF after the & character, the statement fits just one line.
@Echo Off
Echo.
If "%1"=="" (Echo Missing source file & GoTo :EOF)
If not exist %~1 (Echo File %~f1 not found & GoTo :EOF)
If "%2"=="" (Echo Missing destination file & GoTo :EOF)
Set Out=%~f2Echo Parsing %~f1 into %Out%
Echo. > %Out%
For /F "tokens=*" %%A in (%1) Do Call :PARSE %%A
Set Row=
Set Out=
GoTo :EOF:PARSE
If "%1"=="User:" ((Set Row=%2~) & GoTo :EOF)
Shift
:LOOP
Shift
If not "%1"=="" ((Set Row=%Row%%1 ) & GoTo :LOOP)
Echo %Row%>> %Out%
GoTo :EOF

One small problem. When the Full Name contains parentheses like the following it doesn't work. Can you get it to work with the parentheses? Thanks again
Full Name: Tracy H. Johnson (Wistrom)

![]() |
SQL help
|
Memory Management in C++ ...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |