Find the answer to your Linux question:
Results 1 to 3 of 3
For example if i have the following "OneThree" and i want to add the word "Two" between "one" and "three". To have "OneTwoThree" How can i do this?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2009
    Posts
    11

    Using sed, How can I add text between two words?


    For example if i have the following "OneThree" and i want to add the word "Two" between "one" and "three". To have "OneTwoThree" How can i do this?

  2. #2
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    I would replace the words completely. i.e. replace "OneTwo" with "OneTwoThree". One could also replace "One" with "OneTwo" or "Three" with "TwoThree". But these things depend on the overall context.

  3. #3
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,221
    as Kloschüssel said, it depends on context.

    One way of accomplishing this might be:
    Code:
    sed 's;\(^One\)\(Three\)$;\1Two\2;' YOUR_FILE
    You must always face the curtain with a bow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •