So, given that I have some type of data structure like this within a segment of code:
struct apple {
int type, color;
Apple app;
};
// ... more code
I want to take the full struct definition (and any other struct definitions in the file) and compress them into one line (so the file product would look something like:
struct apple { int type, color; Apple app; };
).
This is part of a homework assignment. I just learned sed in lecture not a week or so ago, and I’m very unsure as to how to do something like this. As such, if you feel uncomfortable answering things outright, I would appreciate if you could point me in the right direction so that I can learn how to use this utility correctly.
I’m assuming that one could accomplish things with sed by detecting the struct definition, and then keep reading each line into a global buffer until a } is found (I’m assuming there are no unions or anything in the struct definition). There seems to be a lot of power in this program though, and I can’t find any great introductions to it.
I’d do something in the line of this:
The construct
/foo/,/bar/selects all lines (inclusive) between patterns.The
Ncommand appends a newline and the next line to current pattern space. Then the famouss///command gets executed which replaces the newline character with nothing, i.e. join of lines.