Wednesday, October 15, 2014

Shell Script to generat comma seperated output from a file

#!/bin/bash
counter=1
invoice_clause=""
while read line
do
    if [ $count == 1 ]
    then
    #invoice_clause="'$line'"
        echo "if then"
    else
    invoice_clause="$invoice_clause,'$line'"
    fi
    counter=`expr $counter + 1`
done < invoices.num

echo $invoice_clause


Input file :
one
two
three
four
five

Output:
'one','two','three','four','five'

No comments: