问题
Is there way to curl and grep for an expression while matching a first line (which contains status code) using grep? (Without saving the result of the curl on a file or a variable.)
I am thinking some thing like this but using grep -
curl -is "http://example.com/test.html" | awk 'NR == 1 || /'"JOB_STATUS"'/'
using maybe head and grep
head -n 1 and grep -E "exp[ab]"
回答1:
If your curl output looks something like this:
Status:200
something ... something
JOB_STATUS
you can use:
curl ... | egrep "Status:|JOB_STATUS"
to get the first line and the JOB_STATUS line.
Or, as you have something against awk, maybe sed, like this:
curl ... | sed -ne '1p' -e '/JOB_STATUS/p'
I think you need to show the output of your curl command and explain what's wrong with your awk...
回答2:
curl -is "http"//example.com/test.html" | head -1 | grep -E 'exp[ab]'
来源:https://stackoverflow.com/questions/23375630/curl-and-grep-status-code-and-content-of-the-file