在命令行中格式化文件以进行打印

Ser*_*nyy 3 printing cups lp lpr text-formatting

每当我使用lprorlp命令打印文本文件时,单词在一行的末尾被切断并继续到另一行;例如,'understand' 将在第一行的末尾分成 'unde' 和在另一行的开头的 'rstand'。有没有办法以某种方式证明文件的文本以进行打印?我已经尝试过lpr -p-o media=a4,以及适合页面的选项,但这些词仍然被切断。

对我有用的解决方案:

  1. garethTheRed 的foldfold -s textfile.txt | lpr
  2. fmt命令在这里这里找到:fmt -u -w 80 textfile.txt | lpr; 请注意,宽度 80 可以更改为您喜欢的任何值,但对我来说这似乎工作得很好

gar*_*Red 5

使用fold. man页面摘录:

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
Run Code Online (Sandbox Code Playgroud)

使用fold(可能使用该-s选项,以便它不会在字中断行)将文档设置为大约 80 个字符宽并打印:

fold -s myfile.txt | lpr
Run Code Online (Sandbox Code Playgroud)

或者,要保存格式化的版本:

fold -s myfile.txt > output.txt
Run Code Online (Sandbox Code Playgroud)