Command-Line CSV Viewer
-
Create a new file called
csv
in/usr/bin/
(or in/usr/bin/local/
if it exists in your distro):Terminal window $ sudo vim /usr/bin/csv -
Paste the following code into the file (credit goes to Benjamin Noakes for this code):
#!/usr/bin/env bash# Author: Benjamin Oakes <[email protected]>set -o errexitfunction show_usage {cat <<EOFUsage: $0 [--help] [filename]View a CSV file at the command line.--help Show this help text.filename CSV file to be viewedEOFexit -1}if [ "$1" == "--help" -o "$1" == "" ]; thenshow_usageficat "$1" | column -s, -t | less -#2 -N -S -
Exit vim (good luck!). Make this script executable:
Terminal window $ sudo chmod +x ./csv -
All done! As long as
/usr/bin/
is on yourPATH
, you should be able to nicely display CSV files in the command line with:Terminal window $ csv my_file.csv