Viewing 19 posts - 1 through 19 (of 19 total)
  • DOS experts…. a little help please…
  • bristolbiker
    Free Member

    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…..

    5thElefant
    Free Member

    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).

    SprocketJockey
    Free Member

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

    Fresh Goods Friday 696: The Middling Edition

    Fresh Goods Friday 696: The Middlin...
    Latest Singletrack Videos
    bristolbiker
    Free Member

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

    bristolbiker
    Free Member

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

    mikewsmith
    Free Member

    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…

    SprocketJockey
    Free Member

    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

    bristolbiker
    Free Member

    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……

    SprocketJockey
    Free Member

    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

    bristolbiker
    Free Member

    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.

    EDIT:

    <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…..

    towzer
    Full Member

    ? 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

    SprocketJockey
    Free Member

    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:

    http://www.dostips.com/DtTipsStringManipulation.php

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

    http://stackoverflow.com/questions/14646162/returning-the-surrounding-lines-to-a-string-windows-batch-file

    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

    bristolbiker
    Free Member

    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…..

    brassneck
    Full Member

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

    Or

    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.

    mogrim
    Full Member

    Or install Unix Utils.

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

    http://stackoverflow.com/questions/2701910/windows-batch-file-to-echo-a-specific-line-number

    Russell96
    Full Member

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

    easygirl
    Full Member

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

    bristolbiker
    Free Member

    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!

    BigEaredBiker
    Free Member

    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.