curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' \
| json_pp | sed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p}' curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' \
| json_pp | sed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p}'To run this with macOS, I had to use the GNU version of sed. I installed it with
$ brew install gnu-sed
And it is then called with 'gsed' instead of 'sed'.As an avid Perl programmer, I had json_pp in my $PATH - for everyone else - it is here: https://metacpan.org/pod/JSON::PP
You can install it with cpanm:
$ cpanm JSON::PP
If you don't have cpanm, you can install it with $ curl -L https://cpanmin.us | perl - App::cpanminus
The modified command line from above then becomes: $ curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' \
| json_pp | gsed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p}'
Here is a little Bash function to encapsulate this: $ function c() { curl -sS "https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=$1" | json_pp | gsed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p}'; }
Which then allows you to use it like this: $ c hacker
hacker news
hacker typer
hackerrank
hackerman
hackers movie
hacker fare
hackerone
hackers cast
hacker pschorr
For spaces in your query, use a '+': $ c New+York
new york times
new york and company
new york giants
new york post
new york daily news
new york weather function c() {
url='https://www.google.com/complete/search?client=hp&hl=en&xhr=t'
# NB: user-agent must be specified to get back UTF-8 data!
curl -H 'user-agent: Mozilla/5.0' -sSG --data-urlencode "q=$*" "$url" |
jq -r .[1][][0] |
sed 's,</\?b>,,g'
}
Example: $ c ':)' ':('
) ( meaning
) ( emoticon
) ( ͡° ͜ʖ ͡°)
) ( emoticon meaning sed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p;}'
(Edited to remove previous advice about inserting a newline) $ curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' | jq . | gsed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p}'
(see my other comment about gsed vs sed) curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' | jq -r '.[1] | .[][0] | sub("</?b>"; ""; "gi")' curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' | jq . | sed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p;}'
(Edited to remove previous advice about inserting a newline)There's a blog dedicated to shaming sites that do this: https://curlpipesh.tumblr.com/#_=_
But generally speaking, you're right. You're taking a risk every time you run executable code from the internet, and if you don't want to live in a paranoid state of fear constantly, you have to balance security and convenience. If you check that it says "https" in the beginning and that you trust the source, then you're probably fine.
``` echo "test... test... test..." | perl -e '$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;;y; -/:-@[-`{-};`-{/" -;;s;;$_;see' ```
/s