skip to Main Content

i have been trying for hours but with no luck, I want to extract the (id, remote_ip, listen_addr) and put it in a txt file

I have managed to do so with

curl -s https://pastebin.com/raw/gGt524CS | grep -e "id" -e "remote_ip" -e "listen_addr" | cut -d" -f4 > text.txt

but the result I’m getting is not aligned as it should

I want it to be like that in 10 lines:

id@remote_ip:listen_addr 

The result I’m getting looks like this:

9ed1e069802812f484faa68a2c6dd61f6bc1be0b
tcp://0.0.0.0:26656
88.99.61.173
8f1f37f30546275dea1f1e2a9e3828e8565f118d
tcp://0.0.0.0:26656
212.192.222.35
aac5871efa351872789eef15c2da7a55a68abdad
tcp://0.0.0.0:26656
88.218.226.79
2e8c8d2d7f84b602069fc608a151c19840642d07
tcp://0.0.0.0:26656
95.216.39.183
d4c5dcfbec11d80399bcf18d83a157259ca3efc7
tcp://0.0.0.0:26656
138.201.200.100
d82c661cfec95670271b2e55037e003ff8285741
tcp://0.0.0.0:26656
193.124.50.74
2ecf2dd998aa6fbfef370a027510d0f56026cbc3
tcp://0.0.0.0:26656
152.53.35.92
e4dcdc1218f8703a16f6cc8d7024af2457661198
tcp://0.0.0.0:26656
198.7.125.195
f1ec81f4963e78d06cf54f103cb6ca75e19ea831
tcp://0.0.0.0:26656
217.76.159.104
d6416eb44f9136fc3b03535ae588f63762a67f8e
tcp://0.0.0.0:31656
211.219.19.141

Should be like this:

[email protected]:26656

Thank you all

2

Answers


  1. With jq:

    curl ... | jq -r '.result.peers[] | "(.node_info.id)@(.remote_ip):(.node_info.listen_addr | sub("tcp://0.0.0.0:";""))"'
    

    Output:

    [email protected]:26656
    [email protected]:26656
    [email protected]:26656
    [email protected]:26656
    [email protected]:26656
    [email protected]:26656
    [email protected]:26656
    [email protected]:26656
    [email protected]:26656
    [email protected]:31656
    

    Resources used:

    Login or Signup to reply.
  2. You’d be much better off using a tool that actually understands JSON, like :

    $ xidel -s --input-format=json "https://pastebin.com/raw/gGt524CS" -e '
      $json/result/(peers)()/concat(
        node_info/id,"@",remote_ip,
        substring-after(node_info/listen_addr,"tcp://0.0.0.0")
      )
    '
    

    The pastebin-url returns JSON as text.

    $ xidel -s "https://pastebin.com/raw/gGt524CS" -e '$headers'
    [...]
    Content-Type: text/plain; charset=utf-8
    

    For actual JSON that should’ve been Content-Type: application/json. You can work around that by simply parsing the source with -e 'parse-json($raw)/...', or by forcing the input-format as shown above.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search