2

I've noticed that fmt uses two space characters when joining sentences across lines.

Command:

$ fmt << EOF
Hello world. 
This is a nice place. And a nice website too. I come here
to ask important questions.
Like this one.
EOF

Output:

Hello world.  This is a nice place. And a nice website too. I come here
to ask important questions.  Like this one.

Is there a way to turn this behaviour off and use a single space instead?

I know that there's a long debate whether one should use 1 or 2 spaces after the period. But this is not relevant in my case. I want to only partially reformat existing text files, typeset using 1 space after the period.

| improve this question | | | | |
  • I have done some tests, and it appears that the double space occurs only when a period is followed by a new line, although any multiple spaces mid-sentence are maintained. You can reverse this effect by piping the output through sed 's/\. /. /g'. With your here-document, you'll need to start with { fmt << EOF and add } | sed 's/\. /. /g' on the next line. To remove all multiple spaces, use sed 's/ */ /g' instead (replace space-space asterisk by space, if the format isn't clear). – AFH May 8 '18 at 17:41

Your Answer

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

Browse other questions tagged or ask your own question.