Computing.Net > Forums > Programming > Batch parse text to delimited

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch parse text to delimited

Reply to Message Icon

Name: jgus
Date: August 13, 2004 at 06:26:08 Pacific
OS: Win2K
CPU/Ram: P4
Comment:

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 Nespor

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: August 13, 2004 at 07:51:51 Pacific
Reply:

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=%~f2

Echo 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


0

Response Number 2
Name: jgus
Date: August 13, 2004 at 15:33:04 Pacific
Reply:

Works great!! Thanks a bunch....just what I needed.


0

Response Number 3
Name: jgus
Date: August 17, 2004 at 00:28:21 Pacific
Reply:

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)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


SQL help Memory Management in C++ ...



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch parse text to delimited

Batch file adding text to file also www.computing.net/answers/programming/batch-file-adding-text-to-file-also/16756.html

Batch file: Adding to file names www.computing.net/answers/programming/batch-file-adding-to-file-names/9098.html

Perl script - add text to a jpg ima www.computing.net/answers/programming/perl-script-add-text-to-a-jpg-ima/3331.html