From c3920d64ecb27f578894ff71ec40d761f7c02895 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 7 Apr 2016 14:20:32 +0100 Subject: [PATCH] csv2human --- etc/profile.d/functions | 46 +++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/etc/profile.d/functions b/etc/profile.d/functions index ed704b89..807ddcda 100644 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -412,24 +412,38 @@ csv2human() { declare sep noheader; sep='\t'; noheader=0; + declare files='' + while [ $# -gt 0 ]; do - case "$1" in - --sep|-s) - sep=$2; - shift - ;; - --noheader|-nh) - noheader=1 - ;; - *) - echo "Unknow option: $1 at $0!"; - return -1 - ;; - esac; - shift; - done; + + if [ -e "$1" ]; then + files="$files $1" + shift + continue + fi + + case "$1" in + --sep|-s) + sep=$2; + shift + ;; + --noheader|-nh) + noheader=1 + ;; + *) + echo "Unknow option: $1 at $0!"; + return 1 + ;; + + esac + + shift + + done + [ -z "$@" ] || sep="$@"; - cat | perl -MEncode -F"$sep" -ane 'BEGIN { + + cat $files | perl -MEncode -F"$sep" -ane 'BEGIN { $noheader = shift @ARGV; @len = (); @lines = (); binmode( STDOUT, "utf8:" ); -- 2.47.3