DOS experts…. a little help please…

Home Forum Chat Forum DOS experts…. a little help please…

Viewing 19 posts - 1 through 19 (of 19 total)
  • DOS experts…. a little help please…
  • I have a text file which repetitively contains a specific string. 24 lines after each occurrence of the string is the data I want, and want to copy to a file.

    For a multitude of mundane reasons, this needs to done with a DOS batch file.

    I can search the text file and identify the line number of the target string, and add 24 to that to get to the line number of the data I want. This is all embedded in a loop which I have checked identifies all of the lines I want. Now, knowing the line numbers, whats the easiest way of copying the content of that line to an external file? I’m sure it must be simple, but has been driving me mad for most of the morning.

    Ta in advance…..


    I’m old enough to remember doing that stuff, which means my memory isn’t what it used to be, but…

    …you could do that kind of thing in batch with edlin (which used to be part of dos and may or may not still be available).

    I have a VBS script which does something similar by looking for a keyword – could you call that from your DOS script?

    edlin died after XP – this will be used on Win7 machines. No, the irony is not lost on me…….

    SJ – probably not: ideally the solution needs to be self contained in DOS

    Premier Icon mikewsmith

    edlin died after XP – this will be used on Win7 machines. No, the irony is not lost on me……

    Bow many times do you need to do this? If it’s once do it manually 🙂 can you not launch some kind of program with the file from a dose command line you could even launch a vid of text scrolling through a dose box…

    May be oversimplifying but can you not just use echo to write the output to a new line in your target file?

    echo “hello world” >>c:\test.txt

    Each file is ~50mb is size, containing ~100 lines of interest. Initially there are 10 files to process this may rise to a very large number. I’ve tried manual data extraction on a couple and have been bored to tears……

    If you’re able to set the string to a variable then

    set foo = <insert code to return your value>
    echo foo >>c:\output.txt

    I think the Q is, how do I echo the content of a line when all I know is the line number as an integer? That method would be ideal/simple if I knew the syntax to echo the content of a line number, rather than just a string.


    <insert code to return your value>

    this is the bit I’m struggling with 😉

    Maybe, having identified the line numbers I have to do another for loop to search the file again but only at that line…..actually, that might work…..


    ? is more +n looks helpful

    can you do something clever with for

    for /F %%i in (1.txt) do set FC=%%i

    add a counter and call a second bat that uses the line and the counter

    Really not sure how you do it on a line basis

    Is the string you’re looking to return always a specific length?

    If so you could use Findstr to identify the specfic block of text and then use right to extract the bit you need.

    Some good info on here regarding DOS text manipulation which may be useful:

    Also some stuff here about returning lines around a specific string which you may be able to adapt

    EDIT just noticed an error in the output code I posted earlier:

    set foo= <insert code to return your value>
    echo %foo% >>c:\output.txt

    I found that stackoverflow link and was hoping to do something a bit simpler, as I only require one line, rather than a selection either side of the target string…..

    Premier Icon brassneck

    Install Cygwin and use grep/sed/awk /whatever 🙂


    SED for Windows

    Wot I think you’re trying to do ..

    PERL would be another good bet if this kind of thing crops up often for you.

    I’m sure it’s possible in batch, but text file manipulation usually turns out to be quite hard work relatively speaking.


    Or install Unix Utils.

    This is probably what you’re looking for if that’s not an option:

    Premier Icon Russell96

    If you know the line number then you can use more to display the file starting at that line number

    Premier Icon easygirl

    Flipping eck, I feel numb as a piss stone reading that

    OK sorted now – thanks all. I have something working which is currently a bit of a blunt tool, but has scope for refinement when time permits!

    Premier Icon BigEaredBiker

    Windows 7?

    I am sure I have something in PowerShell to pull what I needed from txt log files. From what I remember it was a lot easier if regular expressions were involved though…

Viewing 19 posts - 1 through 19 (of 19 total)

The topic ‘DOS experts…. a little help please…’ is closed to new replies.