Find sub-string and return it plus previous 17 characters

时间:2017-04-25 14:29:06

标签: java windows vba batch-file

I want to be able to search a text file in Windows for a sting ("A R") and return the every instance of the string plus the previous 17 characters. The characters contain numbers, dashes, and slashes. Unfortunately, the strings that I am looking for are contained in a mess of information, so simply returning each line that "A R" is found on isn't really an option.

I have tried to devise a way to simple use FINDSTR in CMD and redirect the output to a results.txt, but the FINDSTR won't let me pass so many characters (see below).

findstr /r /c:"[0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z][0-Z]A R" CombineXML.txt >results.txt

Results should look something like:

05-24-00-212-805-A R

25-23-00-300-801-A R

79-33-03-400-801-A R

I only have access to NetBeans (not very experienced in Java, though), VBA, and Windows Batch Scripting (company computer = no admin rights, no Python, no Visual Studio...grrr).

I've been racking my brain for a week trying to figure this out.

Any ideas?

1 个答案:

答案 0 :(得分:1)

findstr的能力非常有限,所以在这里没用。但是有一个很好的工具jrepl可以进行各种REGEX搜索和替换。以下行应该做你想要的:

 type CombineXML.txt |JREPL.BAT "(.{17}A R)" "$1" /match >results.txt