Last active
April 4, 2023 17:52
-
-
Save markasoftware/9cd693fa8529142c201303466f150dff to your computer and use it in GitHub Desktop.
Copy CSV to clipboard as table, in shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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