Tuesday, March 23, 2010

Prepend string in bash using sed

You can do that using the following sed command


sed 's/^//g'

The key here is the use of ^ Which matches the start of line.

For example below is how you can prepend "foo" to a string "bar"


echo "bar" | sed 's/^/foo-/g'