Skip to content

Instantly share code, notes, and snippets.

@fabienhinault
Created November 9, 2017 12:37
Show Gist options
  • Save fabienhinault/c1eeb4051a6b2312376d152244fb3715 to your computer and use it in GitHub Desktop.
Save fabienhinault/c1eeb4051a6b2312376d152244fb3715 to your computer and use it in GitHub Desktop.
Transform a json file containing timestamps to add a readable date
mkdir -p /tmp/toto ;
tmpfile=$(mktemp /tmp/toto/data-XXXXXX.json);
ts=$(date -u -d"2017/04/01 00:00:00" "+%s");
curl -X GET --header 'Accept: application/json' "https://host/path?ts=$ts000" | sed 's/"/\\"/g' | sed -r 's/(\.[0-9]{12})([0-9]*)/\1/g' | sed -r 's/(([^0-9][0-9]{0,12})*):([0-9]{10})([0-9]{3}),((:?[0-9]{0,12}[^0-9:])*)/printf "%s%s%s" "\1" ":\\\"\3\4 $(date +%FT%TZ -u -d @\3)\\\"," "\5";/ge' > $tmpfile;
# first sed escapes double quotes, because they will be printed by "print"
# second sed truncate all numbers to 12 digits after point, in order to detect timestamps easier (timestamps here are milliseconds)
# third sed appends to all timestamps, their equivalent dates
firefox $tmpfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment