I'm trying to expand on this question but can't figure out this issue:
Let's say I've got a file roll.txt
:
echo "'123456789','987651234','129873645','213456789','987612345','543216789','432156789','876543291','213465789','542637819','123456','23456','22234','3456','7890543','34567891,'2345','567'" >> roll.txt
I can place a newline after every sixth comma with the following sed command:
sed 's/,/,\n/6; P; D' roll.txt
'123456789','987651234','129873645','213456789','987612345','543216789',
'432156789','876543291','213465789','542637819','123456','23456',
'22234','3456','7890543','34567891,'2345','567'
However, when I try to place two newlines after every sixth comma:
sed 's/,/,\n\n/6; P; D' roll.txt
'123456789','987651234','129873645','213456789','987612345','543216789',
'432156789','876543291','213465789','542637819','123456','23456',
'22234','3456','7890543','34567891,'2345','567'
I instead get two newlines after the sixth comma, and four newlines after the 12th comma. Why? And how can I get two newlines after every sixth comma?
P; D
sequence only prints and deletes up to the first\n
- leaving the second\n
at the beginning of the pattern space. If you have a recent version of GNU sed, try running it with the--debug
option to see what happens. – steeldriver Oct 13 '23 at 01:52