I have a large(20MB) text (input) file with various lines of text (including blank lines) in it. I would like a batch file that can find specific text in the input file, grab the string the search term is in, write that string to another text (output) file AND append that string with a space, comma and the line that follows it in the input file in the output file.
-
INPUT FILE DATA:
NORTHING EASTING O-HEIGHT CODE FFF STATION STD DEV MAPPROJ
NEO 000 020720618 4829559.470 ,12082011c.lst
0.015 0.015 0.015
NEO 000 020740188 4835430.827 ,12082011c.lst0.009 0.009 0.009
NEO 000 020750232 4841535.651 ,12082011c.lst0.004 0.004 0.004
PLH 000 020720615 N 43 36 15.44568 W 79 32 38.22754 67.892 m 0 ,12082011c.lst0.014 0.014 0.014 ,12082011c.lst
-
SEARCH TERM: “NEO”
-
OUTPUT:
NEO 000 020720618 4829559.470 ,12082011c.lst, 0.015 0.015 0.015
NEO 000 020740188 4835430.827 ,12082011c.lst, 0.009 0.009 0.009
NEO 000 020750232 4841535.651 ,12082011c.lst, 0.004 0.004 0.004
I’ve tried using the findstr command and it will write the first part of the line ( NEO 000 020720618 4829559.470 ,12082011c.lst) but I can’t figure out how to grab the next line and append it to the string. (the strings are longer than I’ve shown in this example so if there is a character limit for variables please let me know).
Thanks,
Gabe.
As I indicated in my comment, batch is not a good choice for processing text files. But here is a native batch solution for your problem. I am assuming you are searching for lines where the first token is NEO, not for lines that contain NEO anywhere within.
It looks like you want to ignore the empty lines, which is good because FOR /F ignores empty lines.
This solution will also ignore any line that begins with
;due to the default FOR /F EOL option. This can be eliminated by setting EOL to a linefeed character, but the syntax is ugly. I am assuming you do not have lines that begin with;.As with any batch solution, lines are limited to ~8191 bytes.