Curl, jq and sed

Jul 15, 2020

178 words

Today I’m sharing some cool linux command line tools. Consider them a starting point to learn new things.

To make API requests I use curl.

$ curl -X GET {rest_api} --header "Authorization: Token {token}"

where {rest_api} is the REST API and {token} is the access token. I usually use GET, POST and PATCH to get, create and edit/delete JSON data.

curl together with jq display a more beautiful response.

$ curl -X GET {rest_api} --header "Authorization: {token}" | jq .

where jq . prints the entire object.

sed saves me a lot of time when I need to edit multiple files without opening them one by one.

$ sed -i 's+{source}+{target}+g' {file}

where s is search, g is global and {file} is your file. {source} and {target} is the change you want. To search all files in a directory, replace {file} with *. If you need to search a single line, replace s with 15s, where 15 is the line number.

You may remove a whole line containing the word question.

$ sed -i 's+.*question.*++g' {file}

Play. Learn.




Back to top