Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 9673

Extract rows with specific phrase at specific column from text file using batch file in Windows

$
0
0

I have a text file (epin.txt) having >2 millions of rows.

Sample text:

182060045892569246925460002021    03560000000020000840000000000000ABDRGS00IN0000MMFADT265000 0917 P81 001182060045892585476932540002021    03560000000100000356000000000000PFTSVS00IN0000MMTHRD285000 0997 P81 001182071045892585476932540002021    03560000006905000356000000000000DFRTSS00IN0000BPSYFZ865000 0006 P81 001

I want to extract only those rows with "0600", "0610", "0620" at 4th, 5th, 6th and 7th column to a new text file.

So from the sample only the 1st and 2nd row should be extracted to a new file:

182060045892569246925460002021    03560000000020000840000000000000ABDRGS00IN0000MMFADT265000 0917 P81 001182060045892585476932540002021    03560000000100000356000000000000PFTSVS00IN0000MMTHRD285000 0997 P81 001

I was able to do this using excel but only with file having less than 1 million rows.

Then I tried using FINDSTR:

findstr /B "0600 0610 0620" epin.txt > rf.txt

But this was only working for rows beginning with 0600 or 0610 or 0620;and only with a specific filename.

Can it be improved a bit where it can look for specified phrases starting at Nth character and in any text/csv/flat files (like using wildcard in filename in the code epin***.txt)?


Viewing all articles
Browse latest Browse all 9673

Trending Articles