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.

 
 
» You might also be interested in the following articles:
Manage gzip files on-the-fly (zcommands)
Secure shell (ssh) session timeout
Keep ssh session saved (Unix “screen” utility)
Simple way to transmit files over network (nc utility)
Two-way conversion of Unix time (seconds since 1970) and regular time



» Want to stay up to date? Subscribe to our E-MAIL or RSS feed!

0 Responses to “Linux and Unix fmt utility as a simple text formatter”


  1. No Comments

Leave a Reply




Friendly Sites:Who is behind Linux Screw?
Aspiring Sysadmin | GeekyBits³ | Bash Cures Cancer | TOTMS
Linux Operating System | Small Linux Deployments | My SysAd Blog
The Danesh Project | ZEPY | Linux config Wiki | Planet Sysadmin
The Sys Admin | {buhay sysad} | a non-geek's linux notes
Linux HOWTOs, Tutorials & Projects with Adam Palmer | LinuxAlt.Com
My name is Artem Nosulchik (artiomix AT gmail DOT com) and I'm Linux/Unix, Cisco systems engineer. The main idea of Linux Screw is to share relevant knowledge, skills and observations over The Web. Here you can find a lot of information related to different Linux distributions, FreeBSD, IOS as well as a other Open Source around staff. Read more ››