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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:51:07+00:00 2026-05-21T22:51:07+00:00

Have noticed this a fewtimes when I’m piping something into sed which does not

  • 0

Have noticed this a fewtimes when I’m piping something into sed which does not contain any newlines, sed does not execute.

Example, a stream contains some text (without any newline)

foo

The command:

$echo -n "foo" | sed 's/foo/bar/'

Outputs nothing.

Whereas if I add a newline character to the end of the stream, The command above will output the expected replacement:

$echo "foo" | sed 's/foo/bar/'
bar

I’ve found a lot of situations where I don’t have, and don’t really want a newline character in my stream, but I still want to run a sed replacement.

Any ideas how this can be done would be appreciated.

  • 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-21T22:51:08+00:00Added an answer on May 21, 2026 at 10:51 pm

    What environment are you in? What sed are you using?

    Because here, I’ve got a better sed:

    $ echo -n foo | sed 's/foo/bar/'
    bar$ 
    $ echo -n foo > test.txt
    $ hexdump -C test.txt
    00000000  66 6f 6f                                          |foo|
    00000003
    $ cat test.txt | sed 's/foo/bar/'
    bar$ cat test.txt | sed 's/foo/bar/' | hexdump -C
    00000000  62 61 72                                          |bar|
    00000003
    $ sed --version
    GNU sed version 4.2.1
    Copyright (C) 2009 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
    to the extent permitted by law.
    
    GNU sed home page: <http://www.gnu.org/software/sed/>.
    General help using GNU software: <http://www.gnu.org/gethelp/>.
    E-mail bug reports to: <bug-gnu-utils@gnu.org>.
    Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
    

    Note that one way to get a better sed is to type it as perl -pe, as in:

    $ cat test.txt | perl -pe 's/foo/bar/' | hexdump -C
    00000000  62 61 72                                          |bar|
    00000003
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have noticed that my particular instance of Trac is not running quickly and
I always have noticed this, including in versions before as well. About half way
In context of recent trends in interviews i have noticed that this question arises
I have noticed that the app Reeder is using the UIWebView but ignores this
So I have noticed that things (for lack of a better word) like this
I have noticed this weird behavior in firefox, it seems like font have some
You probably have noticed this behavior on thefreedictionary.com : on double-clicking a word, the
I have noticed that cURL in PHP returns different data when told to output
I have noticed that some apps like Safari and Mail show a loading indicator
I have noticed that regardless of a given script's execution time, every date() call

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.