Linux and Unix fmt utility as a simple text formatter

fmt utility is a part of GNU core utilities and allows to reformat paragraph text writing to standard output. It also can read input from stdin.

Usage example:

Let’s assume you have big one-line text file (all words are placed in one single line and there are no returns characters there at all). In order to format this file with fmt just execute fmt /path/to/file and you’ll get 72 characters wide output like this:

viper@viper-laptop:~$ fmt /tmp/test
The GNU Project was launched in 1984 to develop a complete Unix-like
operating system which is free software: the GNU system. Variants of
the GNU operating system, which use the kernel called Linux, are now
widely used; though these systems are often referred to as “Linux”,
they are more accurately called GNU/Linux systems.

If you’d like to reduce line width and make it 40 chars wide just execute fmt -40 /path/to/file and you’ll get:

viper@viper-laptop:~$ fmt -40 /tmp/test
The GNU Project was launched in 1984 to
develop a complete Unix-like operating
system which is free software: the GNU
system. Variants of the GNU operating
system, which use the kernel called
Linux, are now widely used; though
these systems are often referred to as
“Linux”, they are more accurately
called GNU/Linux systems.

SHARE:
nv-author-image

Stefan Durand

My name is Stefan, I'm the admin of LinuxScrew. I am a full-time Linux/Unix sysadmin, a hobby Python programmer, and a part-time blogger. I post useful guides, tips, and tutorials on common Linux and Programming issues. Feel free to reach out in the comment section.

Leave a Reply

Your email address will not be published. Required fields are marked *