look for DOS Script that help to extract data from text file

Posted on 2005-05-11
Last Modified: 2012-06-27
Hi There,
i am looking for Dos script that can help to extract data (from EOF until a space line marking) from a text file and put the needed data in another new file. I am not good in scripting hope can get a code to reference.

Thank you.
Question by:AlexKhaw
    LVL 3

    Expert Comment

    you could look at the windows help for "FOR"

    otherwise can you be more specific? reading from EOF to a line break would mean you are reading back from the end of the file... is that what you wish to do?

    Author Comment

    Yes. i would like to read from end of file and backward, until i reach a line break.
    LVL 10

    Expert Comment

    You need the unix 'tail' utility which you can get from This URL which provides a download of several of the essential Unix Utilities, ported to Windows.
    for the unix man page.
    in your DOS batch file,
    tail -n 1 filename
    will display the last line of the file, and
    tail -n 1 filename > outputfile
    will pipe the last line into a file of it's own.

    Please note: I have not checked the version of tail at the URL I have included. My original link for the version I currently use is now broken. However, if it is a true port of Unix tail, the above should hold true.

    Regards .. Alan

    LVL 3

    Accepted Solution

    create a file called c:\test.bat
    copy and paste the following code into test.bat and run
    you do not need to edit the code for the first test

    @echo off
    rem just replace test.bat with the name of the file to read,
    rem and result.txt with the name of the file to write.

    set oFile=test.bat
    set sWriteFile=result.txt

    for /F "eol=\delims=\" %%a in (%oFile%) do set sLine=%%a
    echo %sLine% > %sWriteFile%
    echo DATA = %sLine%
    echo DATA successfully written to %sWriteFile%

    rem this is the last line it will be written to file

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now