The problem:
I want to make sure that a certain string appears in a file and also that another string does not appear in the file. If both conditions are met, the command(s) should generate some output.
Here's what I started with:
I have a cronjob that periodically downloads a web page with curl
.
I wanted to be notified whenever a certain text ("inStock':'True") appears in that web page on one line. This part was easy and works well. Here's the cronjob I used:
curl --silent --cookie "myStore=true; storeSelected=131; ipp=25; SortBy=match; rearview=501552" http://www.microcenter.com/product/501552/AIY_VISION_KIT | grep "inStock':'True"
Because this runs as a cronjob, whenever "grep" produces any output (such as "'inStock':'True',"), I will receive an email.
Now another issue came up: If the text ("This product is no longer available") appears on another line of the web page, I don't want to be notified after all.
Any good solutions? It doesn't have to be grep, awk or perl would also be fine.
Here is an example file example.txt
that we can use instead of depending on the particular webpage and curl:
This product is no longer available
'inStock':'True',
So if I run
cat example.txt | grep "inStock: 'true"
it will output
inStock: 'true'
no matter what other lines are in the file. What I want is a command (or multiple commands) that produce no output if the another line in the file contains the text "This product is no longer available".