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 7843151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:29:02+00:00 2026-06-02T16:29:02+00:00

I need to break ‘aaa bbb’ into aaa bbb In one single line of

  • 0

I need to break ‘aaa bbb’ into

aaa
bbb

In one single line of code.
In gnused, I can:

print 'aaa bbb'  | sed 's/ /\n/g'

In bash, I can:

echo 'aaa bbb' | sed 's/ '"/`echo \\\n`/"

But in ksh/zsh, with at&t sed in AIX, none of this works:

print 'aaa bbb' | sed "s/ /`echo -e \\\n`/"
print 'aaa bbb' | sed 's/ '"/`echo \\\n`/"
print 'aaa bbb' | sed "s/ /`echo \\\n`/"

Is there any workaround in sed, with in one line?

  • 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-06-02T16:29:04+00:00Added an answer on June 2, 2026 at 4:29 pm

    Assuming exactly one space in the line:

    sed 'h;s/^[^ ]* //;x;s/ [^ ]*$//;G'
    

    To do this for every space: (I think I am triggering a bug in my local sed here; I couldn’t combine the commands as above)

    $ echo aaa bbb ccc def ghi zzz |
    > sed -e :s -e h -e 's/ .*$//' -e p -e x -e 's/^[^ ]* //' -e ts -e d
    aaa
    bbb
    ccc
    def
    ghi
    zzz
    

    (You can see why GNU sed was extended to handle this case better.) You can do all sorts of things with the hold space, and even more if you use conditional branching (s/.../.../;thereifmatched).

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

Sidebar

Related Questions

I need to add break line in some legend in JFree Chart. I have
For testing purpose, I need to break this captcha: http://wapforum.us/web/img.php As you can see,
Simple enough question, I just need to break through one minimal wall of confusion.
I have a list of US addresses I need to break into city,state, zip
I need to break down a binary number into 4 decimal digits using assembly.
Me again :) I need to break line if it is longer than 78
I need to break apart a large collection of wav files into smaller segments,
I need to break a long text string into smaller pieces approximately once every
I need to break a singly linked list into smaller linked lists after every
I need to break apart a string that always looks like this: something --

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.