3

Whenever I print a text file with the lpr or lp commands, the words are cut off at the end of one line and continue onto the other; for example, 'understand' would be split into 'unde' at the end of line one and 'rstand' at the beginning of other. Is there a way to justify the text of a file somehow for printing ? I've tried lpr -p and -o media=a4, and fit-to-page options, but the words are still cut off.

Solutions that worked for me:

  1. garethTheRed's fold: fold -s textfile.txt | lpr
  2. fmt command found here and here: fmt -u -w 80 textfile.txt | lpr ; note , that width 80 could be changed to whatever you like, but for me this seems to work well enough
5

Use fold. Extracts from the man page:

Wrap  input  lines in each FILE (standard input by default), writing to
standard output.

-b, --bytes
   count bytes rather than columns

-c, --characters
   count characters rather than columns

-s, --spaces
    break at spaces

-w, --width=WIDTH
    use WIDTH columns instead of 80

Use fold (maybe using the -s option so that it doesn't break your lines mid-word) to set your document to about 80 characters wide and print:

fold -s myfile.txt | lpr

Or, to save the formatted version:

fold -s myfile.txt > output.txt
  • also nice is that the 80 char interpretation includes printable consideration of the effects of returns/backspaces/tabs and etc w/ fold. – mikeserv Nov 30 '14 at 9:26
  • Thank u so much! I've been looking for solutions for days! – Alston Jul 5 '17 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.