0

Why are new lines unaffected by the following code?

echo "line 1" > /tmp/xxx
echo "line 2" >> /tmp/xxx
echo "line 3" >> /tmp/xxx
sed  -e 's/\n/\000/g' /tmp/xxx | od -xc

results in:

0000000    696c    656e    3120    6c0a    6e69    2065    0a32    696c
          l   i   n   e       1  \n   l   i   n   e       2  \n   l    i
0000020    656e    3320    000a
          n   e       3  \n
0000025
user939857
  • 377
  • 5
  • 19

1 Answers1

-1

Why are new lines unaffected by the following code?

Because newline is not read to pattern space, as the newline character delimits lines and is not part of the read line.

From POSIX sed:

In default operation, sed cyclically shall append a line of input, less its terminating <newline> character, into the pattern space. [...]

KamilCuk
  • 120,984
  • 8
  • 59
  • 111