On 12/05/2014 07:19 PM, Kevin K wrote:
On Dec 5, 2014, at 9:08 PM, ToddAndMargo <[email protected]> wrote:

Hi All,

This took me an very frustrating hour to figure out.  Especially
since I was looking for something like awk's "-F" command.

I hope this save someone else from pulling their hair out!
(I was trying to do a substitution with a ton of forward slashes
in it from a variable.   AAAAHHHHH!!!!!)

-T



Example of substitute example:


$ echo "$(echo "TRUE" | sed -e 's/TRUE/FALSE/g')"
FALSE

"g" is for "global"



Example with variables (use full quotes):

$ X="abcd"
$ Y="xyz"
$ echo $X | sed -e "s/${X}/${Y}/"
xyz


If a variable uses a "/" inside it, use a different "delimiter" (the
first character after the "s" tells sed what the delimiter is):


$ X="./abcd"
$ Y="./xyz"
$ echo $X | sed -e "s|${X}|${Y}|"
./xyz

This works inside of vi too.

I recall years ago when using “vi’ clones.  Before VIM became popular and I 
would use other clones.  They generally only supported / as a delimiter, and 
using something different (I normally use -) was an example of where their 
compatibility broke down.


Hi Kevin,

This I did not know.  I still use vi a lot too.  Thank
you for sharing!

-T

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to