Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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 need to use fmt to format some text output in Greek, but it does not behave as it does with latin characters. Consider for example the sentences with 15 characters below.

With latin characters:

 $echo "Have a nice day" | fmt -w 16
 Have a nice day

but, strangely, with non-latin characters:

 $echo "Ηαωε α νιψε δαυ" | fmt -w 16
 Ηαωε α
 νιψε δαυ

In fact for the above string, the smallest value that it prints the sentence without line breaks would be -w 28:

 $echo "Ηαωε α νιψε δαυ" | fmt -w 28
 Ηαωε α νιψε δαυ
 $echo "Ηαωε α νιψε δαυ" | fmt -w 27
 Ηαωε α νιψε
 δαυ

Can somebody explain why this happens and how to fix it, if possible?

share|improve this question
up vote 4 down vote accepted

To answer your question, it is not working because Greek characters are non-Latin, Unicode characters, and:

Unlike par, fmt has no Unicode support, ...

https://en.wikipedia.org/wiki/Fmt

Additional notes

The second part of your question on how-to, unfortunately,

Although there seems be a fairly recent technical report regarding how to wrap Unicode, for example Heninger, Unicode Line Breaking Algorithm , 2015-06-01 http://www.unicode.org/reports/tr14/ however this seems to be specification only, no actual implementation or mention of software how-to examples. You could try asking the author via the email listed.

Since the Wikipedia article on fmt referred to par, and it was available via apt-get, I decided to try it on your posted text.

But I was unsuccessful, it still doesn't wrap the way you wish:

$ echo "Ηαωε α νιψε δαυ" | par 16gr
Ηαωε α
νιψε δαυ

The man page was difficult enough that even the author cautioned that it was: not well-written for the end-user, but if you are determined you could try your luck reading it.

share|improve this answer

fmt, as such, generally does not support "non-latin" (in your example, probably UTF-8). You could perhaps use par, which does do this.

Interestingly, the Solaris and FreeBSD manual pages for fmt are very similar, hinting that the program has been unimproved noticeably since the mid-1980s:

par may be available as a package for your system. If not, it is easy to compile, and found here:

http://www.nicemice.net/par/

On the other hand, proper support for UTF-8 in par has been lacking:

share|improve this answer

Your Answer

 
discard

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.