remove ending comma in CSV export - dossier - console collection manager
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit a1caf3c78149748328e3a77277d3917df1b36abb
 (DIR) parent b9634f331f3916bb064b16bddefa64e0486078e7
 (HTM) Author: Solene Rapenne <solene@perso.pw>
       Date:   Thu,  2 Aug 2018 13:22:11 +0200
       
       remove ending comma in CSV export
       
       Diffstat:
         M dossier                             |      15 +++++++++++----
       
       1 file changed, 11 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/dossier b/dossier
       @@ -64,10 +64,10 @@ export_csv() {
            cd "$REPO"
        
            # display header
       -    printf '"identifier",'
       +    printf '"identifier"'
            find . -name '.git' -prune -o -type f -print | cut -d '/' -f 2 | sort | uniq | while read attr
            do
       -        printf '"%s",' $attr
       +        printf ',"%s"' $attr
            done
            printf '\n'
        
       @@ -75,11 +75,18 @@ export_csv() {
            find . -name '.git' -prune -o -type f -print | cut -d '/' -f 3 | sort | uniq | while read id
            do
                printf '"%s",' "$id"
       +        FIRST=0
                find . -name '.git' -prune -o -type f -print | cut -d '/' -f 2 | sort | uniq | while read attr
                do
       +            if [ "$FIRST" -eq 0 ]
       +            then
       +                    FIRST=1
       +            else
       +                    printf ","
       +            fi
                    # for faster processing, we do not check existence of file before
       -            awk '{ printf "\"%s\",",$0}' "${attr}/${id}" 2>/dev/null  \
       -                || printf '"",'
       +            awk '{ printf "\"%s\"",$0}' "${attr}/${id}" 2>/dev/null  \
       +                || printf '""'
                done
                printf '\n'
            done