I am trying to create excel sheet based on multiple files on a root. I read files line by line and append in the final excel sheet.
I am trying this shell script on small files and it worked 100%, but when I try it on the needed files (85MB per each file) I get this error:
(dsadm@DEVDS) /EDWH/XML/Must # XML.sh csv excel_outputfilename
./XML.sh: line 41: fallocate: command not found
./XML.sh: xmalloc: cannot allocate 172035663 bytes (0 bytes allocated)
./XML.sh: xrealloc: cannot reallocate 86013568 bytes (0 bytes allocated)
./XML.sh: xrealloc: cannot reallocate 86021888 bytes (0 bytes allocated)
Note:
The
csv
parameter is the file extensionMy OS and version: Unix AIX 7.1
Here's the script:
#!/usr/bin/bash
#Files Extension#
Ext=$1
#OutPut File Name without extension ex: TEST#
OutPutFileName=$2.xls
function XMLHeader ()
{
echo "<?xml version=\"1.0\"?>
<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"
xmlns:o=\"urn:schemas-microsoft-com:office:office\"
xmlns:x=\"urn:schemas-microsoft-com:office:excel\"
xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"
xmlns:html=\"http://www.w3.org/TR/REC-html40\">"
}
function SheetHeader ()
{
echo "<Worksheet ss:Name=\"Sheet1\">
<Table ss:ExpandedColumnCount=\"2\" ss:ExpandedRowCount=\"2\" x:FullColumns=\"1\" x:FullRows=\"1\">
<Row><Cell><Data ss:Type=\"String\">"
}
function SheetFooter ()
{
echo "</Data></Cell></Row></Table>
</Worksheet>"
}
function XMLFooter ()
{
echo "</Workbook>"
}
####################################################################################
cd /EDWH/Samir/XML/Must;
fallocate -l 1G $OutPutFileName
XMLHeader > $OutPutFileName;
# loop on the exists files to build Worksheet per each file
for Vfile in $(ls | grep .$Ext);
do
echo "<Worksheet ss:Name=\"$Vfile\"><Table>" >> $OutPutFileName
### loop to write the Row
VarRow=`cat $Vfile`
for Row in $(echo $VarRow )
do
echo "<Row>" >> $OutPutFileName
### loop to write the cells
VarCell=`echo $VarRow`
for Cell in $(echo $VarCell | sed "s/,/ /g")
do
echo "<Cell><Data ss:Type=\"String\">$Cell</Data></Cell>" >> $OutPutFileName
done
echo "</Row>" >> $OutPutFileName
done
echo "</Table></Worksheet>" >> $OutPutFileName
done
echo "</Workbook>" >> $OutPutFileName
####################################################################################
exit;
thanks for all
– Ahmed Samir Nov 19 '15 at 10:57instfix -ik IV56170
? – Jeff Schaller Nov 19 '15 at 11:55