我需要一个脚本,将日志文件转换为易于查看的.html文件,可由“任何人”访问。
这是我到目前为止所知道的:
#!/bin/bash
## The purpose of this script is to create .html files from log files, with the ability to optionally GREP for certain strings
if [ "$2" == "" ];
then
echo "Usage : $0 [Source Log file] [Output HTML file] [String to grep (if applicable)]"
exit 255
fi;
LOGFILE=$1
OUTPUTFILE=$2
GREPSTRING=$3
if [ "$3" == "" ];
then
echo "Cat'ing $LOGFILE to $OUTPUTFILE"
LOGCONTENTS=`cat $LOGFILE`
else
echo "Grep'ing for $GREPSTRING in $LOGFILE"
LOGCONTENTS=`grep --color $GREPSTRING $LOGFILE | sed -e "s/^.*$/&1\n/"`
fi;
# Below is the html heading which will be appended to the final .html file
HEADING="<html><body><h1>Log output for: $LOGFILE</h1>"
# Below is the end of the html file
END="</body></html>"
# Below all the prepared variables are stitched together to the OUTPUT/LOG FILE
echo $HEADING > $OUTPUTFILE
echo $LOGCONTENTS >> $OUTPUTFILE
echo $END >> $OUTPUTFILE
# For debugging, enable the lines below
echo $LOGCONTENTS
echo "Done preparing $OUTPUTFILE"
我的问题是,无论我使用多少CAT、GREP、SED等命令,输出都不会保留换行符。输出文件在执行正常的尾部-f或cat时,看起来或多或少与之类似是很重要的。
https://stackoverflow.com/questions/18991126
复制相似问题