1
   curl -i -v --silent \
     -H "Content-Type: application/json" \
     -d '
   {some data>
   }' \
     https://foo  2>&1 |grep  -w '^boo:'    }

I receive

boo: foo

I only want the foo string without whitespace

1
  • 1
    using jq for processing json is safer as grep. Commented Jul 7, 2017 at 18:26

2 Answers 2

1
2>&1 | grep  -w '^boo:' | awk -F' ' '{print $2}'
Sign up to request clarification or add additional context in comments.

Comments

1

You don't need grep + awk . awk can do the grep job without any problem.

for a file like this:

$ cat file1
too: soo
boo: foo
boofoo: wow
boof: nonono
koo: loo

This works fine:

$ awk '/^boo:/{print $2}' file1
foo

awk by default uses whitespace as fields delimiter, so you don't need -F' ' also

In your case just pipe curl to awk: curl ....|awk '/^boo:/{print $2}'

PS: You can also use gnu grep if available like this: grep -Po '^boo: \K.*' file1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.