Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-19-2014, 01:58 PM   #1
LQ Newbie
Registered: May 2012
Location: Germany
Distribution: Arch, AOSP
Posts: 24

Rep: Reputation: 2
sed - line processing depending on previous line match

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.
sed '/\x1b/ {
	}' <logcat.txt >logcat2.txt
It produces this output:
PHP Code:
[COLOR="Blue"]D/dalvikvm(10103): VFYreplacing 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): VFYreplacing opcode 0x70 at 0x0002
/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.
Attached Files
File Type: txt logcat.txt (2.4 KB, 2 views)

Last edited by BeachHead; 06-19-2014 at 02:01 PM.
Old 06-19-2014, 08:21 PM   #2
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,544

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Well if it can be done I am sure one of the sed-ninjas will jump in, but for such task I would probably use awk, ruby or perl as sed, I find, is a bit clumsy in the method to save data while processing
the next line and so on
Old 06-19-2014, 09:27 PM   #3
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,873

Rep: Reputation: 2190Reputation: 2190Reputation: 2190Reputation: 2190Reputation: 2190Reputation: 2190Reputation: 2190Reputation: 2190Reputation: 2190Reputation: 2190Reputation: 2190
My first reaction is "why do you care" ?.
If the possibility exists for long runs of the same colour, I would post-process to get rid of the "duplicates" - much easier than holding several/many lines until a mismatch. I'd probably use awk, but almost anything will do - post-process should only need to manage 2 lines at a time.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
sed multiple lines previous line gushnik1 Linux - Software 2 10-09-2013 03:15 AM
[SOLVED] Adding a character in each line depending upon number of such characters present in a line. ls_milkyway Linux - Newbie 13 08-24-2013 03:19 AM
[SOLVED] SED replace line after match r00t Linux - Newbie 12 05-31-2012 07:17 AM
Insert line on match only once with sed? lhouk Programming 38 08-10-2010 09:23 AM
grep/sed/awk - find match, then match on next line gctaylor1 Programming 3 07-11-2007 08:55 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:52 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration