Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6648045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:36:33+00:00 2026-05-26T00:36:33+00:00

So, given that I have some type of data structure like this within a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:36:34+00:00Added an answer on May 26, 2026 at 12:36 am

    I’d do something in the line of this:

    $ sed -n '/struct/,/};/p' input | sed -e ':a;N;$!ba;s/\n//g'
    struct apple {    int type, color;    Apple app;};
    

    The construct /foo/,/bar/ selects all lines (inclusive) between patterns.

    The N command appends a newline and the next line to current pattern space. Then the famous s/// command gets executed which replaces the newline character with nothing, i.e. join of lines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some configuration data that I'd like to model in code as so:
Given that I have this resultset structure (superfluous fields have been stripped) Id |
I have been given a task of inputting some student data, like option 1:
I have a XML file template like this that comes from some IC chips,
cowboy coder needs some help from SO-veterans: I have a given application that uses
I have some code that gives a user id to a utility that then
I have some points (about 3000) and edges (about 6000) in this type of
I have a case here that I would like to have some opinions from
I have a large tree-like data structure of objects which behave mostly identical but
Given that I have the data types data A a = A a data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.