Search code examples
linuxshellunixscripting

Convert .csv to Excel file and email as attachment


I'm trying to convert a .csv file to Excel using unix shell script. Tried replacing pipe delimited to comma separated using the below script.

#!/bin/bash
cd /main/subpath/dev/Int/Source/adm/at/csv_xls
for f in *.csv; do 
sed 's/^\||/,/g' "$f" > "${f%.csv}.xls"
done
ls *.csv;
echo "CSV Excel Con" | mailx -s "Testing CSV2Excel" -a "${f%.csv}.xls" [email protected]

I have multiple Excel files. I need to send all the Excel files as email attachments. When I tried using this script it is attaching only one file.


Solution

  • You can simply use [.]

    . file1.csv file1.xlsx