Jams
Jams

Reputation: 4067

Grep all status apart from "200" from curl output

Shell script of mine has "n" number of curl commands and whose output would be displayed as below :

"n" number of status would be displayed based on my "for loop".

From this output i want to grep all the status apart from "HTTP/1.1 200 OK" and then writing it to a file. Pls help me. I am stuck.

upload completely sent off: 74 out of 74 bytes
 HTTP/1.1 500 Internal Server Error
 Content-Security-Policy: 
 Content-Type: text/plain

 HTTP/1.1 200 OK
 Content-Security-Policy: default-src 'self'
 Content-Type: text/plain

Upvotes: 0

Views: 3094

Answers (1)

Kent
Kent

Reputation: 195079

if you want to extract those "blocks" which don't contain 200 Status, grep is not the right tool, since it does line based matching.

give this one-liner a try:

awk -v RS="" '!/ 200 OK/ input> output

If you just want to grab those status lines,E.g. HTTP/1.1 500 Inter.... you can try :

grep -P 'HTTP/1\.1(?!\s*200 OK)' input

Upvotes: 1

Related Questions