Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I often find it useful to print text using

echo 'stuff' | lpr

The lpr output does get hard to read whenever the text is more than small paragraphs; So I would like to add left and right margins to the text. A simple right margin fix is

echo 'stuff' | fmt -w 55 | lpr

This however does not add any margin to the left of the text.

Is there a simple way to achieve this?

share|improve this question
up vote 1 down vote accepted

There is also a -w option for fmt which sets the maximum width of a line and the -s option to split long lines. The default for -w is 75 characters. My quick solution would be something similar to this:

cat [stuff] | fmt -sw 50 | awk '{printf "   "$0"\n"}' | lpr

Here fmt limits the characters per line (in this example 50) and divides long lines automatically. Then this output is piped to awk which adds as many spaces as there are between the first quotation marks after printf, then puts the line from fmt and eventually makes a line break by "\n".

I am sure that it can be done with awk solely, however I was so biased by your fmt that I kept it. I will add an EDIT as soon as I have an expression with awk only.


share|improve this answer
If you indent lines by 4 spaces, they'll be marked as a code sample. You can use backticks ` to mark your inline code. You can also highlight the code and click the "code" button (with "{}" on it). – N.N. Oct 27 '11 at 12:16
I ended up writing a small c++ app letting me practise argp a little. – Captain Giraffe Oct 27 '11 at 17:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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