Skip to content

Instantly share code, notes, and snippets.

@TomLous
Last active June 14, 2022 12:39
Show Gist options
  • Save TomLous/082733b4f96407e4571ff82b29a26dbe to your computer and use it in GitHub Desktop.
Save TomLous/082733b4f96407e4571ff82b29a26dbe to your computer and use it in GitHub Desktop.
Stream the content of a remote file to a locahost port with custom interval
ncat localhost 8888
while read line; do \
sleep .7; \
echo $line | \
tr -d '\r' | \
jq --compact-output --raw-input --raw-output 'split(",") | {"airline": .[0], "airlineId": (.[1]|tonumber? // null), "sourceAirport": .[2], "sourceAirportId": (.[3]|tonumber? // null), "destinationAirport": .[4], "destinationAirportId": (.[5]|tonumber? // null), "codeshare": .[6], "stops": (.[7]|tonumber? // null), "equipment": .[8]}'; \
done < <(curl -s https://raw.githubusercontent.com/jpatokal/openflights/master/data/routes.dat) | \
ncat -lk 8888
@TomLous
Copy link
Author

TomLous commented Jun 14, 2022

Reads the contents from a remote CSV, removes \r, creates a custom json record and starts streaming it with a fixed interval to port 8888 on localhost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment