0

I' m trying to use the Gnuwin32 grep command to produce a list of files I would like to feed to another command (a Perl script really). I have a bunch of HTML files and I wish to list every one of them that matches the regexp itemprop=['"]description.

Now, after some fiddling, I've found that the cmd.exe invocation

grep -i -E -l "itemprop=['\"]description" path/to/files/*.htm

works fine, but I can't pipe its output to perl (or any other command, for that matter):

grep -i -E -l "itemprop=['\"]description" path/to/files/*.htm | perl myscript.pl

prints a list of files to terminal, followed by

grep: |: No such file or directory grep: perl: No such file or directory myscript.pl

grep treats | and subsequent words as arguments. How do I avoid that?

Furthermore, I tried to overcome the issue with Powershell. I can pipe just fine from there (if I use an elementary expression, like "itemprop"), but I have trouble specifying the expression to search for.

grep -i -E -l "itemprop=['\"]description" path/to/files/*.htm just doesn't work. Powershell shows me a >> sign I don't even know what it means (expecting more input)? I've tried every manner of escaping quotes but none seems to work. Sometimes it's the shell, sometimes it's grep that's complaining for an unmatched [ character.

Any help is greatly appreciated.

1 Answer 1

0

It seems you have found a collision on how quotes are handled by the different parsers involved. The simplest way to solve this case is just to escape the closing quote of the grep search expression

grep -iEl "itemprop=['\"]description^" path/to/files/*.htm | perl myscript.pl
1
  • Very nice, though I don't see why I should escape the closing quote instead of the middle one. In the meantime, I've found another form that works, namely grep -iEl "itemprop=['\\""]description" path/to/files/*.htm | perl myscript.pl which seems to make a bit of sense once you get around to that crazy escape in the middle. Also note that neither method works in Powershell.
    – valerio
    Oct 22, 2015 at 3:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .