0

I'm trying to run the following command in windows. I've managed to install cURL, but Grep still fails to identify as a command.

curl -k --silent "http://192.168.1.135:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=USERNAME&pwd=PASSWORD" \
| grep -oP "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)"

Is there an alternative command or a way to install Grep onto Windows?

Update I've installed Grep and added the following to my Path variables, both system and user, and restarted to no avail. C:\Program Files (x86)\GnuWin32

phuclv
  • 30,396
  • 15
  • 136
  • 260
Seudonym
  • 151

2 Answers2

0

I've installed Grep and added the following to my Path variables, both system and user, and restarted to no avail.

A couple things to remember:

  • As @barlop comments, the path should be e.g. C:\Program Files (x86)\GnuWin32\bin.

  • It is perfectly fine to specify the whole path to grep e.g.:

    curl -k --silent "http://192.168.1.135:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=USERNAME&pwd=PASSWORD" | "C:\Program Files (x86)\GnuWin32\bin\grep.exe" -oP "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)"

Anaksunaman
  • 18,227
0

PowerShell's Select-String (alias sls) already has regex matching capability, and curl has been built into Windows, therefore no 3rd party tools need to be installed. Just run this

(curl.exe -k --silent "http://192.168.1.135:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=USERNAME&pwd=PASSWORD" `
| sls "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)").Matches.Value

Note that (?<=motionDetectAlarm>) is a lookahead that matches motionDetectAlarm> and not <motionDetectAlarm> so your regex might be slightly incorrect

phuclv
  • 30,396
  • 15
  • 136
  • 260