Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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...

share|improve this question
    
Could you please show the full grep command as well. –  bbaja42 Oct 19 '12 at 12:57
    
i could and i did :) –  NoSenseEtAl Oct 19 '12 at 13:07

1 Answer 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.

share|improve this answer
    
is the regex semantics the same for my example (in grep and PS) –  NoSenseEtAl Oct 19 '12 at 12:38
    
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 Oct 19 '12 at 12:44
    
btw it still freezes –  NoSenseEtAl Oct 19 '12 at 12:46
    
Could you give more details on the data sample, like size in MB? –  bbaja42 Oct 19 '12 at 12:47
    
btw maybe PS tries to go through directories while grep skips them "X is a directory" –  NoSenseEtAl Oct 19 '12 at 12:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.