Re: Newline Character Missing in Memory Variable

"Thierry Blanc [email protected] [sed-users]" <[email protected]> Sat, 21 May 2016 17:43:08 +0200
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
echo removes newline, if unquoted.

See the difference

$ $a="line 1
line 2
line3"
$ echo $a
$ echo "$a"


On 21/05/16 17:36, n22e113 [email protected] [sed-users] wrote:
> Hello, Seders,
> File /tmp/file contains:
> Line 1
> Line 2
> Line 3
> Line 4
> Line 5
>
> $ sed -n '/^Line 2$/,/^Line 4$/p' /tmp/file returns
> Line 2
> Line 3
> Line 4
>
> However, spaces had replaced '\n':
> $ InMem=$(sed -n '/^Line 2$/,/^Line 4$/p' /tmp/file) && echo -e $InMem returns:
> Line 2 Line 3 Line 4
>
> and InMem='Line 2 Line 3 Line 4' and not
> InMem='Line 2\nLine 3\nLine 4'?
>
> Q1. Can I physically add '\n' in the sed command above?
> Q2. Why the difference in behaviour?
> Many thanks!
> Kwon
>
>
> ------------------------------------
> Posted by: n22e113 <[email protected]>
> ------------------------------------
>



------------------------------------

------------------------------------

-- 

------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/sed-users/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/sed-users/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo Groups is subject to:
    https://info.yahoo.com/legal/us/yahoo/utos/terms/