现在我有了这个 shell 代码,我需要将 HTML 标记添加到简单的文本中。换句话说,我需要将文本格式化为基本的 HTML 代码。
现在我有了这个 shell 脚本:
#!/bin/sh
# t2h {$1} html-ize a text file and save as foo.htm
NL="
"
cat $1 \
| sed -e 's/ at / at /g' \
| sed -e 's/[[:cntrl:]]/ /g'\
| sed -e 's/^[[:space:]]*$//g' \
| sed -e '/^$/{'"$NL"'N'"$NL"'/^\n$/D'"$NL"'}' \
| sed -e 's/^$/<\/UL><P>/g' \
| sed -e '/<P>$/{'"$NL"'N'"$NL"'s/\n//'"$NL"'}'\
| sed -e 's/<P>[[:space:]]*"/<P><UL>"/' \
| sed -e 's/^[[:space:]]*-/<BR> -/g' \
| sed -e 's/http:\/\/[[:graph:]\.\/]*/<A HREF="&">[&]<\/A> /g'\
> foo.htm
这是一个文本示例:
"Greatest properly off ham exercise all. Unsatiable invitation its possession nor off. All difficulty estimating unreserved increasing the solicitude. Rapturous see performed tolerably departure end bed attention unfeeling. On unpleasing principles alteration of. Be at performed preferred determine collected. Him nay acuteness discourse listening estimable our law. Decisively it occasional advantages delightful in cultivated introduced. Like law mean form are sang loud lady put. "
"Greatest properly off ham exercise all. Unsatiable invitation its possession nor off. All difficulty estimating unreserved increasing the solicitude. Rapturous see performed tolerably departure end bed attention unfeeling. On unpleasing principles alteration of. Be at performed preferred determine collected. Him nay acuteness discourse listening estimable our law. Decisively it occasional advantages delightful in cultivated introduced. Like law mean form are sang loud lady put. "
它需要是这样的:
<html>
<p>Greatest properly off ham exercise all. Unsatiable invitation its possession nor off. All difficulty estimating unreserved increasing the solicitude. Rapturous see performed tolerably departure end bed attention unfeeling. On unpleasing principles alteration of. Be at performed preferred determine collected. Him nay acuteness discourse listening estimable our law. Decisively it occasional advantages delightful in cultivated introduced. Like law mean form are sang loud lady put.</p><br />
<br />
<p>Greatest properly off ham exercise all. Unsatiable invitation its possession nor off. All difficulty estimating unreserved increasing the solicitude. Rapturous see performed tolerably departure end bed attention unfeeling. On unpleasing principles alteration of. Be at performed preferred determine collected. Him nay acuteness discourse listening estimable our law. Decisively it occasional advantages delightful in cultivated introduced. Like law mean form are sang loud lady put.</p>
</html>