Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Insert search string back to the result in sed

Answer:

Following command will replace "foo" by "bar", using the sed.

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

But how to append the word "foo" at the end of "bar"?

Here is the solution with the & (& defines the pattern found in the search string)

# echo "foo" | sed 's/foo/bar&/'

  1. Speedup sed search and replace
  2. Search and replace string in file using Perl
  3. Search the history of commands you have executed
  4. Case conversion of string in Linux
  5. How to echo string to standard error (stderr)?

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>