Skip to content

Instantly share code, notes, and snippets.

@stantonk
Last active October 5, 2015 22:07
Show Gist options
  • Save stantonk/2884411 to your computer and use it in GitHub Desktop.
Save stantonk/2884411 to your computer and use it in GitHub Desktop.
Read a list of values separated by newlines from stdin and output the values on a single line separated by commas to stdout
#!/usr/bin/env bash
######
# Why is this useful?
#
# Say you have a list of ids in a database tool like SequelPro in
# the result of a query. It is possible to copy an entire column
# to the clipboard. But then you may want to pass that list of
# ids as a comma-separated list into an HTTP(S) API endpoint for
# testing. This solves that problem!
#
# Example:
# Let's say your clipboard contains "123\n456\n\789\n"
# $ pbpaste | csv | pbcopy
#
# This changes your clipboard to contain:
# "123,456,789"
#
# Now you can plop it into a URL:
#
# http://someapi.com/some/api/endpoint/123,456,789/metadata
pbpaste | tr '\n' ',' | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment