SCIENTIFIC-LINUX-USERS Archives

December 2014

SCIENTIFIC-LINUX-USERS@LISTSERV.FNAL.GOV

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
ToddAndMargo <[log in to unmask]>
Reply To:
ToddAndMargo <[log in to unmask]>
Date:
Fri, 5 Dec 2014 19:08:34 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (40 lines)
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

ATOM RSS1 RSS2