Re: Batch Script Text file parse

Discussion in 'Scripting' started by Pegasus [MVP], Mar 24, 2009.

  1. <> wrote in message
    news:...
    > 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?
     
    Pegasus [MVP], Mar 24, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sbillard

    Script To Parse A Text File?

    sbillard, Aug 10, 2004, in forum: Scripting
    Replies:
    0
    Views:
    245
    sbillard
    Aug 10, 2004
  2. MMC-Michelle
    Replies:
    2
    Views:
    1,164
    MMC-Michelle
    Mar 5, 2007
  3. Al Dunbar
    Replies:
    2
    Views:
    1,202
    Al Dunbar
    Jan 27, 2009
  4. Richard Mueller [MVP]

    Re: Batch Script Text file parse

    Richard Mueller [MVP], Mar 24, 2009, in forum: Scripting
    Replies:
    0
    Views:
    836
    Richard Mueller [MVP]
    Mar 24, 2009
  5. Replies:
    0
    Views:
    481
Loading...

Share This Page