Hallo,
i'm trying to convert a colored Android system log (logcat with ANSI escape sequences) to vbulletin color codes. My first script looks like this and works so far but is not optimal due to duplicates.
Code:
sed '/\x1b/ {
s/\x1b\[0m\x1b\[38;5;40m/\[COLOR="Green"\]/
s/\x1b\[0m\x1b\[38;5;196m/\[COLOR="Red"\]/
s/\x1b\[0m\x1b\[38;5;75m/\[COLOR="Blue"\]/
s/\x1b\[0m\x1b\[38;5;166m/\[COLOR="Sienna"\]/
s/\x1b\[0m\x1b\[38;5;231m/\[COLOR="DarkSlateGray"\]/
s/\x1b\[38;5;40m/\[COLOR="Green"\]/
s/\x1b\[38;5;196m/\[COLOR="Red"\]/
s/\x1b\[38;5;75m/\[COLOR="Blue"\]/
s/\x1b\[38;5;166m/\[COLOR="Sienna"\]/
s/\x1b\[38;5;231m/\[COLOR="DarkSlateGray"\]/
s/\x1b\[0m/\[COLOR="Black"\]/
s/$/\[\/COLOR\]/
}' <logcat.txt >logcat2.txt
It produces this output:
PHP Code:
[COLOR="Blue"]D/dalvikvm(10103): VFY: replacing opcode 0x70 at 0x0002[/COLOR]
[COLOR="Blue"]D/dalvikvm(10103): JIT code cache reset in 0 ms (0 bytes 2/0)[/COLOR]
But it should rather look like this:
PHP Code:
[COLOR="Blue"]D/dalvikvm(10103): VFY: replacing opcode 0x70 at 0x0002
D/dalvikvm(10103): JIT code cache reset in 0 ms (0 bytes 2/0)[/COLOR]
Now i'm wondering what's the best method to accomplish that optimization. Is there a text processor already that can process multilines with hold&replace pattern match? Or should i do it manually with bash (conditional loops, previous pattern pushed into variables...)?
Any ideas?
Example logcat is attached.
.