Only with grep
will not be able to get the string in the format you need ( numero - url
). With the help of the awk
tool it is easier:
curl -s 'http://brasil.br/pub/retorno.json' | grep -Po '"(numero|url)": "\K[^"]*' | awk 'NR%2{ printf "%s - ", $0; next;}1'
Due to some limitations of lookbehind, such as accepting only fixed-length expressions, I made a slight modification to the regular expression. \K
serves as a good alternative for lookbehind, since it is more flexible and still allows us to ignore everything that is before it, since it only makes what is after it is considered in the result of the expression.
awk
is a very useful tool for filtering texts. We are using awk
for every two lines, they are printed in linha_atual - linha_seguinte
format.