fmt command in linux with example

In this tutorial, I use fmt command to formatting a file, setting the column with and formatting uniform spaces.

What does fmt mean?

fmt – simple optimal text formatter

Syntax

fmt [-WIDTH] [OPTION]... [FILE]...

In man page the describe it

  • fmt – simple optimal text formatter.
  • man fmt – More details information about fmt command.

fmt command in linux with example

By default fmt sets the column width at 75.

I have created a file fmt_command.txt

[vagrant@DevopsRoles ~]$ cat fmt_command.txt 
 HuuPV, My website DevopsRoles.com and HuuPhan.com.SN:199x.
 Devops Roles.
 Hello world. xxx.

fmt with no options

[vagrant@DevopsRoles ~]$ fmt fmt_command.txt 
HuuPV, My website DevopsRoles.com and HuuPhan.com.SN:199x.  Devops Roles.

Hello world. xxx.

How to change the width of formatting.

[vagrant@DevopsRoles ~]$ fmt --width 20 fmt_command.txt 
 HuuPV, My website
 DevopsRoles.com and
 HuuPhan.com.SN:199x.
 Devops Roles.
 Hello world. xxx.

with -u option uses one space between words and two spaces after sentences for formatting.

[vagrant@DevopsRoles ~]$ fmt -u fmt_command.txt 
 HuuPV, My website DevopsRoles.com and HuuPhan.com.SN:199x.  Devops Roles.
 Hello world. xxx.

Conclusion

fmt command is the simple command in Linux. It is used to formatting a file, setting the column with and formatting uniform spaces.

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

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

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.