Replacement using sed
Given repeated record like :
Code:
Object Code:
00 90 00 00 00 00 ... Code:
00 90 45 23 00 00 ... Code:
sed '/trace/,/dump/d' Code:
00 90 00 00 00 00 ... |
Can you show an example of the output you desire? If you could show what else you want to see besides the pairs of digits that would help. Meanwhile, let me suggest that filtering with grep can simplify your sed tasks.
|
I think you need to explain further your desired output as what you have seems to fit what you require?
|
Here's an awk solution:
awk '$0 ~ /^dump/ {print "Title"; flag=1} {if($flag==0) { if($0 ~ /trace/) { flag=1 } else { print $0 } } }' Output: Quote:
|
I was going to say the same thing :) It seems like, based on what you have explained, that sed is doing what it should. It sounds like you want a record looking like this:
Object dump 00 90 00 00 00 00 ... 00 00 90 90 00 00 ... trace: [<sss>]lslsl [<lsl>]ksksk Object dump 00 90 45 23 00 00 ... 00 00 90 90 00 00 ... trace: [<sss>]lslsl [<lsl>]ksksk Object dump 00 90 55 44 00 00 ... 00 00 90 90 00 00 ... trace: [<sss>]lslsl [<lsl>]ksksk To end up looking like this: 00 90 00 00 00 00 ... 00 00 90 90 00 00 ... 00 90 45 23 00 00 ... 00 00 90 90 00 00 ... 00 90 55 44 00 00 ... 00 00 90 90 00 00 ... To test this, I created a text file (test.txt) with your original example, then used "cat" while piping your sed command. Testing your original command like this: cat test.txt |sed '/trace/,/dump/d' did what it seems like you would want it to do, except it left the top two lines of the original file. In order to remove those two lines also, I modified the command to use sed twice like this: sed '/trace/,/dump/d' | sed '/Object/,/dump/d' Then it removed everything except for the lines between dump and trace. Is this what you're looking for? If not, please explain more. |
@matthewetaft: Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
Actually, it sounds to me like he wants each section to be separated by at least one blank line. This can be done by telling sed to append a line (blank or otherwise) to the matched section before deleting it. There's also no need to use two sed commands; just use one with multiple "-e" options. Code:
sed -e '/trace/,/dump/ {/dump/ a It is also possible to reduce it to a single expression, however: Code:
sed -r -e '/(trace|Object)/,/dump/ {/dump/a |
All times are GMT -5. The time now is 02:39 PM. |