Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple pretty CSV and TSV file viewer.
#####################################################
# Bash functions to put in .bashrc or .bash_aliases #
#####################################################
# For Debian/Ubuntu
function pretty_csv {
column -t -s, -n "$@" | less -F -S -X -K
}
function pretty_tsv {
column -t -s $'\t' -n "$@" | less -F -S -X -K
}
# For non-Debian systems
function pretty_csv {
perl -pe 's/((?<=,)|(?<=^)),/ ,/g;' "$@" | column -t -s, | less -F -S -X -K
}
function pretty_tsv {
perl -pe 's/((?<=\t)|(?<=^))\t/ \t/g;' "$@" | column -t -s $'\t' | less -F -S -X -K
}
#!/bin/bash
perl -pe 's/((?<=,)|(?<=^)),/ ,/g;' "$@" | column -t -s, | exec less -F -S -X -K
#!/bin/bash
perl -pe 's/((?<=\t)|(?<=^))\t/ \t/g;' "$@" | column -t -s $'\t' | exec less -F -S -X -K
@heshriti

This comment has been minimized.

Copy link

@heshriti heshriti commented Oct 28, 2018

Hi, this is a great utility. Thank you.

When working with large files, we can use pager/less command to look through all the data. However, the header (i.e. first line) is lost when you scroll to the second page.

Is it possible to modify your function so that pretty_csv can output a table, with a "frozen" header- one that keeps the header when you scroll through the data.

@yangyxt

This comment has been minimized.

Copy link

@yangyxt yangyxt commented Jun 17, 2020

Thank you for providing this! But I failed to present the tsv with pretty_tsv.sh script.
Here is what I get:
image
Here is what the table originally looks like:
image

It seems the table only show the first column with pretty_tsv.

@soxofaan

This comment has been minimized.

Copy link
Owner Author

@soxofaan soxofaan commented Jun 18, 2020

@yangyxt: given the "line ... is too long" warnings, I just think that your file is corrupt or at least has very wide columns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.