我想采取html片段并将其传递给pygmentize以相应地着色。我想知道如何使用sed或其他cli工具来实现这一目标。sed multiline pygmentize
我尝试了一堆的sed单行的,并试图使用以下SO问题:
- Sed multiline replacement question
- Using or in multiline sed replacement
- sed or awk multiline replace
我有以下的日志:
2012-03-26 18:04:27,385 9372 [main] ERROR web.commons.exception.ServiceInvocationException -
Response from server cannot be decoded to JSON, responsePayload = <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing jetty-url. Reason:
<pre> Not Found</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
</body>
</html>
org.codehaus.jackson.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: [email protected]; line: 1, column: 2]
UPDATE我加入这一个较长的命令:
mvn -U test | (while read line; do echo ${line} | sed -e "s/.*ERROR.*/`echo -e '\e[91m&\e[0m'`/g" -e "s/.*\(WARN|INFO\).*/`echo -e '\e[93m&\e[0m'`/g"; done)
你需要在END模式中跳过'/'。另外,考虑到用户的样本输入,我认为你的解决方案将包括看起来在同一行上的开头''前面的非html文本。祝你们好运。 – shellter 2012-03-26 22:52:55
嗯。这很奇怪。在预览中显示逃生。在最后的答案,它不是! – John3136 2012-03-26 22:56:17
嘿,这很酷,但仍然有第一行的输入,它将成为一个更长的命令的一部分。尽管你的回答仍然非常有帮助,但这可能有点过分。如果它太多,我可能会创建一个python程序来提供一些帮助。 – prafulfillment 2012-03-26 23:09:17