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:50:15 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (61 lines)
On 12/05/2014 07:19 PM, Kevin K wrote:
>> On Dec 5, 2014, at 9:08 PM, ToddAndMargo <[log in to unmask]> 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ATOM RSS1 RSS2