Skip to content

Instantly share code, notes, and snippets.

@nordri
Last active September 30, 2019 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nordri/fa8ed836abfc39b5a7eeda9dbc4a093b to your computer and use it in GitHub Desktop.
Save nordri/fa8ed836abfc39b5a7eeda9dbc4a093b to your computer and use it in GitHub Desktop.
Convert tab separate file (TSV) to JSON with jq

Input file

echo -e "i-0b9adca882e5e6326\t	172.16.0.188
i-088dd69e5c3624888\t	172.16.0.102
i-0e70eac180537d4aa\t 172.16.0.85" > input.tsv

Command

cat input.tsv | jq --raw-input --slurp 'split("\n") | map(split("\t")) | .[0:-1] | map( { "id": .[0], "ip": .[1] } )'

Output

[
  {
    "id": "i-0b9adca882e5e6326",
    "ip": "172.16.0.188"
  },
  {
    "id": "i-088dd69e5c3624888",
    "ip": "172.16.0.102"
  },
  {
    "id": "i-0e70eac180537d4aa",
    "ip": "172.16.0.85"
  }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment