Findstr regexp

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Findstr regexp

#1 Post by Squashman » 02 Oct 2015 23:26

All these years and I still do not understand Regular Expressions. Must need to be a Rocket Surgeon.

Just want all records where the 8th comma delimited field has store in it.
Tried this and it gave me records with the 8th field, but also records where store was in the 10th field.

Code: Select all

findstr /B /R ".*,.*,.*,.*,.*,.*,.*,Store," test.txt

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Findstr regexp

#2 Post by Squashman » 03 Oct 2015 00:09

Understanding Regular Expressions is a fricken lost cause for me!!!!! Getting really pissed off because I can do this shit in SAS but can't seem to get the syntax right using FINDSTR or JREPL!

Neither of these worked.

Code: Select all

jrepl "(.*?,){7}Store," "" /b /f test.txt

jrepl ".*?,.*?,.*?,.*?,.*?,.*?,.*?,Store," "" /b /f test.txt

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Findstr regexp

#3 Post by aGerman » 03 Oct 2015 05:23

Squashman

. is for "any character" where a comma is an "any character" as well :wink:
What you're looking for is "any character that is not a comma".
Try

Code: Select all

findstr /br "[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,Store," "test.txt"


Regards
aGerman

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Findstr regexp

#4 Post by dbenham » 03 Oct 2015 18:57

It is even simpler when you have a a utility with a proper regex implementation that allows you to specify a match count.

Using JREPL:

Code: Select all

jrepl "^([^,]*,){7}Store,.*" "$0" /jmatch /f "test.xt"


Dave Benham

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Findstr regexp

#5 Post by Squashman » 05 Oct 2015 12:26

Thanks guys!!! Helped out a lot.

Post Reply