0

I would like to take the html piece and pass it to pygmentize to colorize it accordingly. I'm wondering how I could use sed or some other cli tool to get that accomplished.

I tried a bunch of sed one-liners and tried to use the following SO questions:

I have the following log:

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: java.io.StringReader@369133f6; line: 1, column: 2]

UPDATE I'm adding this to a longer command:

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)
Community
  • 1
  • 1
prafulfillment
  • 911
  • 2
  • 11
  • 26

3 Answers3

2

cat log | awk '/<html>/,/<\/html>/'

Should do it.

To remove the "crap" before the first html tag, get sed to put the html tag on it's own line.

cat log | sed 's/<html>/\n<html>/' | awk '/<html>/,/<\/html>/'

John3136
  • 28,809
  • 4
  • 51
  • 69
  • you'll need to escape the '/' in the END pattern. Also, given the user's sample input, I think your solution will include the non-html text the precedes the opening `` that looks to be on the same line. Good luck to all. – shellter Mar 26 '12 at 22:52
  • Hmm. thats odd. On the preview the escape shows. on the final answer, it doesn't! – John3136 Mar 26 '12 at 22:56
  • Hey this cool but still has the first line's input and it's going to be part of a longer command. This might be overkill though your answer is still very helpful. I might create a python program to provide some help if it's too much. – prafulfillment Mar 26 '12 at 23:09
  • I'll edit it to handle the start bit. Standby (good fun for a Tuesday morning ;-) – John3136 Mar 26 '12 at 23:26
0

I used this as part of a longer command:

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)
prafulfillment
  • 911
  • 2
  • 11
  • 26
0

TXR:

For illustration purposes, we replace pygmentize with a command that replaces every letter in the HTML with X.

@;; replace with .e.g. pygmentize
@(bind filter "tr [A-Za-z] X")
@date @time @pid [@function] @error_1
@error_2 <html>
@(collect)
@stuff
@(last)
</html>
@(end)

@error_3
@(output)
@date @time @pid [@function] @error_1
@error_2
@(end)
@(output `!@filter`)
<html>
@{stuff "\n"}
</html>
@(end)
@(output)
@error_3
@(end)

Test run:

$ txr  log.txr  log.txt
2012-03-26 18:04:27,385 9372 [main] ERROR web.commons.exception.ServiceInvocationException  -
Response from server cannot be decoded to JSON, responsePayload =
<XXXX>
<XXXX>
<XXXX XXXX-XXXXX="XXXXXXX-XXXX" XXXXXXX="XXXX/XXXX; XXXXXXX=XXX-8859-1"/>
<XXXXX>XXXXX 404 XXX XXXXX</XXXXX>
</XXXX>
<XXXX><X2>XXXX XXXXX 404</X2>
<X>XXXXXXX XXXXXXXXX XXXXX-XXX. XXXXXX:
<XXX>    XXX XXXXX</XXX></X><XX /><X><XXXXX>XXXXXXX XX XXXXX://</XXXXX></X><XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>
<XX/>

</XXXX>
</XXXX>
org.codehaus.jackson.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
Kaz
  • 55,781
  • 9
  • 100
  • 149