-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq2.sh
More file actions
executable file
·24 lines (22 loc) · 1.02 KB
/
q2.sh
File metadata and controls
executable file
·24 lines (22 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
INPUT_FILE=$1
OUTPUT_FILE="heart.tex"
echo "\documentclass{article}" > $OUTPUT_FILE
echo "\usepackage{graphicx}" >> $OUTPUT_FILE
echo "\begin{document}" >> $OUTPUT_FILE
echo "\begin{table}[h!]" >> $OUTPUT_FILE
echo "\centering" >> $OUTPUT_FILE
echo "\begin{tabular}{|l|l|l|l|l|l|l|l|l|l|l|l|l|l|}" >> $OUTPUT_FILE
echo "\hline" >> $OUTPUT_FILE
# Read the CSV header and format as LaTeX table header
HEADER=$(head -n 1 $INPUT_FILE)
echo $HEADER | awk -F',' '{for(i=1;i<=NF;i++) printf "%s & ", $i}' | sed 's/& $/\\\\ \\hline/' >> $OUTPUT_FILE
tail -n +2 $INPUT_FILE | while IFS=',' read -r col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 col11 col12 col13 col14
do
echo "$col1 & $col2 & $col3 & $col4 & $col5 & $col6 & $col7 & $col8 & $col9 & $col10 & $col11 &$col12 & $col13 & $col14 \\\\ \\hline" >> $OUTPUT_FILE
done
echo "\end{tabular}" >> $OUTPUT_FILE
echo "\caption{Heart Disease Data}" >> $OUTPUT_FILE
echo "\end{table}" >> $OUTPUT_FILE
echo "\end{document}" >> $OUTPUT_FILE
echo "LaTeX file $OUTPUT_FILE generated."