Skip to content

Instantly share code, notes, and snippets.

@markasoftware
Last active April 4, 2023 17:52
Show Gist options
  • Save markasoftware/9cd693fa8529142c201303466f150dff to your computer and use it in GitHub Desktop.
Save markasoftware/9cd693fa8529142c201303466f150dff to your computer and use it in GitHub Desktop.
Copy CSV to clipboard as table, in shell
#!/bin/bash
# Use input redirection. Copies straight to clipboard.
# Can paste into spreadsheet applications directly.
# MIT licensed.
gawk '
BEGIN { FPAT = "([^,]*)|(\"[^\"]+\")" }
NR>1 { print "" }
{
for (i = 1; i <= NF; i++) {
if (substr($i, 1, 1) == "\"") {
len = length($i)
$i = substr($i, 2, len - 2)
}
printf "%s",$i
if (i != NF) {
printf "\t"
}
}
}
' | xclip -selection clipboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment