- 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…..Posted 4 years agomikewsmithSubscriber
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…Posted 4 years ago
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…..Posted 4 years ago
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>Posted 4 years ago
echo %foo% >>c:\output.txtbrassneckSubscriber
Install Cygwin and use grep/sed/awk /whatever 🙂
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.Posted 4 years agomogrimMember
Or install Unix Utils.
This is probably what you’re looking for if that’s not an option:Posted 4 years ago
The topic ‘DOS experts…. a little help please…’ is closed to new replies.