Preface: Convert the data in the text to html data with the help of script, use cat << CLOUD #Here-document usage
For example: info.txt text data is
ZhangSan:Shang Hai
LiSi:
BeiJing WangWu:TianJin
The script code of Txt2Html.sh is:
#!/bin/bash
cat << CLOUD #Here-document usage, CLOUD is a delimiter
<!DOCTYPE html> #html header document declaration, if here-document is not used, an error will be reported
<html>
<head>
<title>
user information
< /title>
</head>
<body>
<table>
CLOUD #Create HTML file header template that is <!DOCTYPE html> to <table>
#Replace the domain separator (:) with </TD><TD>
#where ^ $ is the beginning and end of each line of the regular expression
sed -e 's/:/<\/TD><TD>/g' -e 's/^/<TR><TD>/g' -e 's/ $/<\/TD><\/TR>/g'
cat << CLOUD
</table>
</body>
</html>
CLOUD #Create HTML file header template that is </table> to </html>
Execute the linux command:
chmod u+x Txt2Html.sh #Add execute permission in root state
#Redirect the data in info.txt to Txt2Html.sh, and then redirect the data in Txt2Html.sh to info.html
./Txt2Html.sh < info.txt > info.html
cat info.html #View the contents of the info.html file