Powershell 2 freezing on Select-String ".*_.*=-1"

1

this might seem like stupid Q but I have PS problem: like the title says I try something like:

 $all = gci D:\work\
 $all | Select-String ".*_.*=-1"

(im looking for config option that has value -1 and _ in name) Problem is that PS freezes, aka it doesnt finish in reasonable time, ctrl +c doesnt work. Ofc you could say that data is just to much for it to process, but problem is that grep takes like 1-2 secs on same folder and same regex.

Grep command is (originally it didnt have -r but I added it after some comments, grep is still fast but it takes 20-30 sec)

grep ".*_.*=-1" -r D:\work\*

EDIT:

$all  | ForEach-Object {echo $_.Name;  $_|Select-String ".*_.*=-1"      }

shows slowly filenames... I guess the problem is that Regex speed in PS is pathetic...

NoSenseEtAl

Posted 2012-10-19T12:19:47.443

Reputation: 194

Could you please show the full grep command as well. – bbaja42 – 2012-10-19T12:57:40.360

i could and i did :) – NoSenseEtAl – 2012-10-19T13:07:05.573

Answers

1

Specific:
Try tweaking a regex to

 [^_]*_[^=]*=-1

equivalent grep version :

grep -P '[^_]*_[^=]*=-1'

General:
The regex implementations are different, so that is the reason for different behavior. I don't know specifics of powershell regex implementation, so I don't know the exact reason.

bbaja42

Posted 2012-10-19T12:19:47.443

Reputation: 2 815

is the regex semantics the same for my example (in grep and PS) – NoSenseEtAl – 2012-10-19T12:38:43.313

I don't know. Even grep as more than 1 regular expression syntax. Regular, extended and perl version. I'm not experienced with the PS version. – bbaja42 – 2012-10-19T12:44:04.433

btw it still freezes – NoSenseEtAl – 2012-10-19T12:46:30.013

Could you give more details on the data sample, like size in MB? – bbaja42 – 2012-10-19T12:47:43.930

btw maybe PS tries to go through directories while grep skips them "X is a directory" – NoSenseEtAl – 2012-10-19T12:48:34.427

idk how to get total size, but all has ~500 entries – NoSenseEtAl – 2012-10-19T12:49:33.113

Grep does not go recursively, unless -r flag is given. – bbaja42 – 2012-10-19T12:49:34.083