Curl and grep status code and content of the file

假装没事ソ 提交于 2020-01-25 14:26:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!