samplefile.txt를 html 테이블 형식으로 변환하고 싶습니다. 모든 특수 문자를 무시해야합니다. ###
의 시작 부분은 표 머리글에 들어가야하지만 내용은 표 셀 내부의 표 머리글.리눅스 셸 스크립팅에서 텍스트 파일 데이터를 html 테이블 형식으로 변환하는 방법
또한이 스크립트에서 표제 및 표 테두리의 서식을 지정하고 싶습니다.
이 간단한 samplefile.txt입니다 :
###File1
###File2
###File3
###Sports
Y|Cricket|Football|basketball
Y|beach volleyball|boxing|diving
Y|cycling|Batminton|Swimming
###Country
$|United States|United Kingdom|India
$|Peru|Japan|Poland
이 난에서 작업 된 스크립트입니다 - 어떻게 든이 코드는 100 % 작동하지 않습니다는 :
#!/bin/sh
tableflag=0
echo "<html>"
echo "<body>"
while read line
do
#echo $line
heading=`echo $line | cut -c-3`
headdata=`echo $line | cut -c4-`
if [ "$heading" == "###" ]; then
#if [ $tableflag -eq 1 ]; then
#echo "</table>"
#fi
echo "<th colspan="3" style="font-family: 'Times New Roman';"> $headdata </th>"
echo '<tr> </tr>'
echo '<table border="1" style="width:80%;margin:30px">'
else
tableflag=1
echo '<tr>'
echo "$line" | awk -F"|" '{print "<td>" $2 "</td><td>" $3"</td><td>"$4"</td>"}'
echo '</tr>'
echo '<tr> </tr>'
fi
done < samplefile.txt
echo "</table>"
echo "</body>"
echo "</html>"
희망에 열 병합을 설정합니다 .. – user6690412