Skip to content

Instantly share code, notes, and snippets.

@lacek
Last active October 31, 2017 03:15
Show Gist options
  • Save lacek/70aaf521d7b41fbb74cad96a3600b7b3 to your computer and use it in GitHub Desktop.
Save lacek/70aaf521d7b41fbb74cad96a3600b7b3 to your computer and use it in GitHub Desktop.
#!/bin/bash
show_help()
{
cat <<EOB
Usage: ${0##*/} [-h] [-t sep] [-n num] file
Display a row in CSV file with header vertially.
Options:
-t specify field separator, default is tab
-n specify line to show, default is 1
EOB
}
sep=$'\t'
num=1
OPTIND=1
while getopts hn:t: opt; do
case "$opt" in
h)
show_help
exit 0
;;
n)
num=$OPTARG
;;
t)
sep=$OPTARG
;;
*)
show_help
exit 1
;;
esac
done
csv=${@:$OPTIND:1}
if [[ ! -f "$csv" ]]; then
show_help
exit 1
fi
num=$((num+1))
paste <(gunzip -cf "$csv" | head -1 | tr "$sep" '\n') <(gunzip -cf "$csv" | tail -n+$num | head -1 | tr "$sep" '\n') | column -ts"$sep"
# vi:syntax=bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment