Quick question for coding and sed/awk geniuses..

Haus

<Silver Donator>
11,027
41,641
I have a problem.

I have a large data files I need to feed through a parser but the data files is a little misformatted.

The section I need to parse looks like this :

: (ReferenceObject
:Name (damned_object_name)
:Table (network_objects)
:Uid ("{169F8374-BD52-44F2-86E6-952579B8F5FB}")
)

And the parser is expecting :

: damned_object_name

Part of my head is saying there has to be some easy peasy way with sed/awk in linux or with some decently advanced editor on windows (like notepad++) to have it convert the file into something the parser can handle, but my brain isn't seeing it yet. Don't have access to tinker with the parser or else I would have done it on that end.

If someone can come up with a way to do this easily I have a $25 amazon gift card i'll post as a bounty. I just have too much on my plate to dive into this one at the moment... Also been too busy to find some chesty lady to get a RR post it note on her tits and a pic else I would have posted that instead...

Haus
 

Chancellor Alkorin

Part-Time Sith
<Granularity Engineer>
6,029
5,915
You only need the : damned_object_name, and not the rest?
 

Haus

<Silver Donator>
11,027
41,641
You only need the : damned_object_name, and not the rest?
Exactly!

It's the "remove the line before it and lines after" that is getting me. And these "ReferenceObject" sections are nestled in a file full of other things and I only need to touch/change the ReferenceObject sections.
 

Haus

<Silver Donator>
11,027
41,641
How's this:

Looks near perfect. I need to work some tabs in though. Damn formatting and me forgetting to do it in code..

The actual look like this :
Tried working in the three tabs in front of ReferenceObject as \t\t\t but it didn't like that... hurm.
 

Haus

<Silver Donator>
11,027
41,641
Tried stripping out all the leading spaces in the source file and still didn't take... odd
 

Chancellor Alkorin

Part-Time Sith
<Granularity Engineer>
6,029
5,915
Those are 3 tabs in the replacement string at the end. Not sure what you wanted.
 

Chancellor Alkorin

Part-Time Sith
<Granularity Engineer>
6,029
5,915
Nah. He wants the whole file to be returned with certain lines edited.
 

Haus

<Silver Donator>
11,027
41,641
Sir, you are a genius, gentleman, and scholar. PM me an e-mail address that I might send you your Amazonian Bounty!
 

Melvin

Blackwing Lair Raider
1,399
1,168
Ah, I'd probably do that in python then because I've never gotten around to learning sed for shit.
 

Chancellor Alkorin

Part-Time Sith
<Granularity Engineer>
6,029
5,915
Yeah, I'd probably have done that in perl myself, but it's amazing how quickly awk/sed can do things if the syntax is right.
 

Desidero

N00b
163
2
If anyone else is going to have to look at the replacement command/script in the future and you want readability, gawk might be a bit nicer. This script will also preserve the spacing of the original so it's not always 3 tabs like the sed command that was provided.

Code with comments:
"One liner" format if you don't want to use gawk -f <script file> <input file> for whatever reason:
 

Chancellor Alkorin

Part-Time Sith
<Granularity Engineer>
6,029
5,915
Good call. Never used gawk before.

This one will preserve spacing as well (from the ReferenceObject line):

 

Desidero

N00b
163
2
Crazy people using cat for no reason... Also, your regex will erroneously modify lines if there's a string like ': (ReferenceObject' anywhere in a non-reference object block. Probably better to only look for spaces and tabs before the colon. Getting the spaces before the ReferenceObject colon instead of the Name colon is probably more correct though, so good job there.
 

Chancellor Alkorin

Part-Time Sith
<Granularity Engineer>
6,029
5,915
I can't even remember why I'm used to using cat like that. I've done it that way for longer than I can remember. Probably a (questionably bad) habit I picked up at some point when I was learning.

Yeah, there's a lot of questionable regex there. This wasn't meant to be multi-purpose. I'd have to have been a lot more careful if that were the case. I'm not sure if you can do a multiline check on the first sed expression there, but I guess you should be able to? Seems it might cause chaos if I'm joining lines during the check, though. Meh...
 

Desidero

N00b
163
2
That's why I usually fall back on (g)awk when things involve multiple lines. Sed can do it, but it gets ugly really fast.