In a file like:
ruler 1 2 3 4 5 6 7 8
12345678901234567890123456789012345678901234567890123456789012345678901234567890
\usage{
function(
parameter,
parameterparameter,
parameter = parameter,
parameter = p,
parameter = para,
parameter = para,
paramete = p,
parameterparameter = pa,
parameter = p,
p = pa,
param,
parameterpara = par,
paramet = par,
parameter = param,
parameterpa = param,
...
more lines
I want to concatenate lines from line with "usage" to the line with "...", and then, create new line breaks after commas before the 80th character (column).
For now, I manage to break lines after the nth comma, but it is not efficient because in many cases a lot of spaces remain after, say, the 3rd comma. So I want the comma before the line break to be as close as possible to the 80th character.
sed -i -r '/usage/{:a;N;/\.\.\./!ba;s/\n//g}' filename.txt
sed -i 's/\(\([^,]\+,\)\{3\}\)/\1\n/g;s/\n/\n/g' filename.txt
I looked at "par", "fold" and "fmt" documentation without success. "fold" gets near but splits lines in space not comma:
sed -i -r '/usage/{:a;N;/\.\.\./!ba;s/\n//g}' filename.txt
fold -s filename.txt | tee filename.txt