balupton
balupton

Reputation: 48709

How to use gfmt to wrap lines maintaining indentation?

Encountered some weird behaviour with GNU Coreutils fmt (gfmt)

> gfmt -t -w 10 <<< $'1 2 3 4 5 6 7 8 9\nb\n c'
1 2 3 4
   5 6 7
   8 9
b c

> gfmt -s -w 10 <<< $'1 2 3 4 5 6 7 8 9\nb\n c'
1 2 3 4 5
6 7 8 9
b
 c

So in the first example, we have a desired indentation of wrapped lines. However, it then nukes the newline with space between b and c. We can use -s to wrap and maintain that newline-space, however it no longer indents the wrapped lines. I have tried -st however, it has no effect:

> gfmt -st -w 10 <<< $'1 2 3 4 5 6 7 8 9\nb\n c'
1 2 3 4 5
6 7 8 9
b
 c

This is a contrived extracted example from a much more complicated situation that requires the following output:

1 2 3 4
   5 6 7
   8 9
b
 c

If an alternative to gfmt is available that resolves this, I will also consider that.

Upvotes: 0

Views: 9

Answers (0)

Related Questions