Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: Batch Script Text file parse

Reply
Thread Tools Display Modes

Re: Batch Script Text file parse

 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      03-24-2009

<> wrote in message
news:231436ae-72ed-499e-a100-...
> Newbie here.
>
> I am trying to get a single line of text from each file within a
> directory of text files.
>
> Example
>
> I have directory X that contains files:
>
> file1.txt
> file2.txt
> file3.txt
>
> Each text file is similar in structure, and contains lines like:
>
> Some mumbo jumbo
> Uniqe ID: xyzpdq
> some other mumbo jumbo
> etc, etc, etc.
>
> In all cases, line 2 contains "Unique ID:" and then the unique
> identifier text, which is what I need to extract.
> In the above case, I need the "xyzpdq". Note that this is what
> changes in each test file.
>
> I want to run a script that will parse either this unique ID, or the
> entire 2nd line of text (in which case I can just trim it later) -
> from all .txt files within the folder.
>
> any help?
>
> Thanks.


Here is a batch file solution:
@echo off
for %%a in ("d:\temp\*.txt") do call :Sub %%a
goto :eof

:Sub
for /F "skip=1 tokens=3" %%b in ('type "%*"') do (
echo %* %%b & goto :eof
)

Its advantage is that it's simple. It's drawback is that it's slow and that
it will probably trip over so-called "poison characters". If you want
something robust and fast then a VB Script file would be a better solution.
How about having a go at it yourself, then requesting specific advice here
instead of asking for the whole thing to be delivered on a platter?


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Batch Script to parse lines in text file rush3rd@gmail.com Scripting 0 03-31-2013 01:28 AM
Re: Batch Script Text file parse Richard Mueller [MVP] Scripting 0 03-24-2009 05:38 PM
Re: Batch Script to parse lines in text file Al Dunbar Scripting 2 01-27-2009 10:51 PM
Script To Parse A Text File? sbillard Scripting 0 08-10-2004 09:27 PM