首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从日志文件创建.html文件

从日志文件创建.html文件
EN

Stack Overflow用户
提问于 2013-09-25 04:10:08
回答 3查看 6.7K关注 0票数 2

我需要一个脚本,将日志文件转换为易于查看的.html文件,可由“任何人”访问。

这是我到目前为止所知道的:

代码语言:javascript
复制
#!/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时,看起来或多或少与之类似是很重要的。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18991126

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档