The length of line-wrapping when using the l
command is implementation defined.
From the standard:
Long lines shall be folded, with the point of folding indicated by writing a followed by a ; the length at which folding occurs is unspecified, but should be appropriate for the output device.
GNU sed
provides the -l
option to specify the length at which to split long lines when printing with the l
command, defaulting to seventy characters.
$ yes | head -c100 | tr '\n' ' ' | sed -n l | head -n1 | wc -c
71
$ yes | head -c100 | tr '\n' ' ' | sed -nl50 l | head -n1 | wc -c
51
BSD sed
splits long lines at the number provided by the environment variable COLUMNS
, if COLUMNS
is not provided then it splits at the terminal width, and if COULMNS
is not provided and the output is not a terminal then it defaults to sixty characters.
$ yes | head -c100 | tr '\n' ' ' | sed -n l | head -n1 | wc -c
61
$ yes | head -c100 | tr '\n' ' ' | COLUMNS=50 sed -n l | head -n1 | wc -c
51
$ yes | head -c100 | tr '\n' ' ' | sed -n l | head -n1
y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y\
y y y y y y y y y y $