0

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]"
surajz
  • 3,471
  • 3
  • 32
  • 38

2 Answers2

2
curl -is "http"//example.com/test.html" | head -1 | grep -E 'exp[ab]'
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • That does not work. head -1 returns the first line and this line is passed to grep. I want the rest of content to be passed through grep. I can do something like "grep -E "^HTTP/1.1|exp[ab]" to get what I want, but just wanted to know if that was possible. – surajz Apr 29 '14 at 21:46
  • Your question isn't very clear. Can you post sample input and desired output? – Barmar Apr 29 '14 at 21:51
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...

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432