We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
fmt command in Linux with examples
fmt command in LINUX actually works as a formatter for simplifying and optimizing text files. Formatting of text files can also be done manually, but it can be really time-consuming when it comes to large text files, this is where fmt comes to rescue. fmt re-formats each paragraph in the file specified, writing to standard output. Here’s the syntax of fmt command:
syntax of `fmt` command in Linux
fmt [-WIDTH] [OPTION]... [FILE]...
where, the -WIDTH is an abbreviated firm of –width=DIGITS and OPTION refers to the options compatible with the fmt command and FILE refers to the file name. If no FILE is specified, or if FILE is a dash(“-“), fmt reads from the standard input.
Using fmt command
fmt by default with no option used format all the words present in the given file in a single line.
cat kt.txt
Used `cat` command to view the content in this file name `kt.txt`
fmt kt.txt
Used `fmt` command to view the content in single line.
fmt kt.txt
To save or write the formatted output you can use fmt as:
fmt kt.txt > dv.txt
Here we have use `>` to save the output in filename `dv.txt`