n22e113 n22e113@yahoo.ca [sed-users]
2016-05-21 15:36:36 UTC
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
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