0

Par is a great tool to format text.

Par joins text and format it to the new size.

Can Par also justify text without joining lines?

p.e.

text text text text
text2 text2 text2 text2
txt txt txt txt txt 

justify to 30

text     text     text    text
text2   text2   text2    text2
txt    txt    txt    txt   txt 

I've read the manual without finding the solution.

Reman
  • 221
  • 2
  • 9

1 Answers1

1

I suspect the nearest you can get with par is to use the j1 option in conjunction with a very carefully chosen w value.

From http://www.nicemice.net/par/par-doc.var

j[<just>]   If <just> is 1, par justifies the OP, inserting spaces
            between words so that all lines in the OP have length
            <width> (except the last, if <last> is 0).  Defaults to
            0.  (See also the w, l, and f options.)

par behaves rather pathalogically with your example text, I think it incorrectly detects a line prefix.

$ cat test2.txt
text text text text
text2 text2 text2 text2
txt txt txt txt txt

The best I could get out of it was

$ ./par -w23 -j1 -p0 -h0 <test2.txt
text  text   text  text
text2 text2 text2 text2
txt txt txt txt txt

I think I'd try perl, with maybe Text::Autoformat and feed autoformat one line at a time.


That idea led me to the rather ugly but fairly effective

$ perl -pe 's/$/\r\n123456789 123456789 123456789 /;' test2.txt| \
> ./par -w30 -j1 -l1 -p0 -h0 | \
> perl -ne 'print unless /^123456789 123456789 123456789 $/'
text    text     text    text
text2   text2   text2   text2
txt    txt   txt    txt   txt

I can't help feeling that a far more elegant solution is available.

RedGrittyBrick
  • 81,981
  • 20
  • 135
  • 205