text - How to replace a pattern with newline (\n) with sed under UNIX / Linux operating systems? -
i have txt file contains:
some random text here. file has multiple lines. should 1 line.
i use:
sed '{:q;n;s/\n/:sl:/g;t q}' file1.txt > singleline.txt
and get:
some random:sl:text here. file:sl:has multiple lines. should 1 line.
now want replace :sl:
pattern newline (\n)
character. when use:
sed 's/:sl:/&\n/g' singleline.txt
i get:
some random:sl: text here. file:sl: has multiple lines. should 1 line.
how replace pattern newline character instead of adding newline character after pattern?
sed uses &
shortcut matched pattern. replacing :s1:
:s1:\n
.
change sed command this:
sed 's/:sl:/\n/g' singleline.txt
Comments
Post a Comment