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

  • Home
  • SEARCH
  • 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 4607780
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:45:03+00:00 2026-05-22T00:45:03+00:00

I am very new to sed and so even with looking at examples I

  • 0

I am very new to sed and so even with looking at examples I am totally at a loss as how to go about writing the correct code for my need (this one is close but it seems not for multi-line replacement.

Here is my input.txt

This is a test of splitting…

|firstword|secondwordthirdword
fourthwordfifthwordsixthword

This is a test of splitting…

firstword|secondword|thirdword
fourthwordfifthwordsixthword

This is a test of splitting…

firstwordsecondword|thirdword|
fourthwordfifthwordsixthword

This is a test of splitting…

firstwordsecondwordthirdword
|fourthword|fifthwordsixthword

This is a test of splitting…

firstwordsecondwordthirdword
fourthword|fifthword|sixthword

This is a test of splitting…

firstwordsecondwordthirdword
fourthwordfifthword|sixthword|

What I need to do is remove all text outside of the two “|” and keep the text inside of the two “|”

And then insert a Unicode zero-width-space between each of the words (U+200B)

Resulting in:

firstwordU+200BsecondwordU+200BthirdwordU+200BfourthwordU+200BfifthwordU+200Bsixthword

I tried

sed '\|/d;/|/,$d' input.txt

UPDATE: Which doesn’t do much

And

sed -e 's/.*|\([^]]*\)|.*/\1/g' input.txt

Which comes close, but doesn’t remove anything from lines that do not contain a “|” (I need to remove everything not contained inside two “|” And I don’t know how to go about adding the zero-width-space between words. But like I said, I don’t really know what I am doing.

Any help would be much appreciated.

-Nathan

  • 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-22T00:45:04+00:00Added an answer on May 22, 2026 at 12:45 am

    If you are happy with the results of

    sed -e 's/.*|\([^]]*\)|.*/\1/g' input.txt
    

    other than its failure to remove lines that do not contain the delimiters, then just do:

    sed -n -e 's/.*|\([^]]*\)|.*/\1/gp' input.txt
    

    to only print lines in which the replace happens. Or, you can explicitly delete the unwanted lines:

    sed -e '/|.*|/!d' -e 's/.*|\([^]]*\)|.*/\1/g'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im very new to jquery/javascript. So here goes, I found this js code for
Very new to jQuery, if dupe question sorry at this point not even sure
Very new to python and can't understand why this isn't working. I have a
Very new to FluentNHibernate, but I'm also excited about the area. I've recently started
Very new to XSL (and XML for that matter), but I need to step
Very new to using Raphael.js I'm looking at the tutorials and I am able
Im very new in C++ I have found this post http://msdn.microsoft.com/en-us/magazine/cc163486.aspx and trying to
Very new to this, and I have no idea where to start. I want
I am very new to bash. So if this is a pretty basic question,
Very new to Fitnesse, I need to write a test using regular expressions to

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.