(defn

haluk-dogan

"Posts About Functional Programming, Machine Learning, and Linux"

[ Home About Archives RSS ]

Bash Functions

September 30, 2019 | By Haluk Dogan

I heavily use two bash functions I defined. listcols is for listing columns along with its column index, and prettycsv is for displaying delimited files nicely formatted in the terminal.

 function listcols {
    local arg sep
    sep=","
    while getopts 's:' arg
    do
        case ${arg} in
            s) sep=${OPTARG};;
            *) return 1 # illegal option
        esac
    done
    shift $((OPTIND -1))
    awk -F$sep '{for (i = 1; i <= NF; i++) print i":", $i; exit}' $@
}
 
 function prettycsv {
    local arg sep
    sep=","
    while getopts 's:' arg
    do
        case ${arg} in
            s) sep=${OPTARG};;
            *) return 1 # illegal option
        esac
    done
    shift $((OPTIND -1))
    column -t -s$sep -n "$@" | less -N -F -S -X -K
}
 

Tags: bash linux

)

Copyright © Haluk Dogan