- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to format contents of a text file in the Linux system?
Sometimes our text files are not well format to represent. This work can be done manually for small file, but if the file is too large then manually formatting is so tough work. In such a case to format the contents of a text file in the Linux operating system, we use the fmt command.
The fmt command is used to format, simplifying, and optimizing text files in the Linux system. If the file is not specified then the fmt command reads input from standard input. By default, the fmt command creates text to a width of 75 characters wide.
The general syntax of the fmt command is as follows −
fmt [-WIDTH] [OPTION]... [FILE]...
Brief description of options available in the fmt command.
|Sr.No.||Option & Description|
Preserve the indentation of the first two lines
Reformat beginning lines with specified STRING, reattaching the prefix to reformatted lines.
Split only long lines, but don’t refill
|4||-t, --tagged-paragraph |
Indentation of first-line different from second
One space between words, two after sentences
|6||-w, --width=WIDTH |
Maximum line width (default of 75 columns)
|7||-g, --goal=WIDTH |
Goal width (default of 93% of width)
Displays a help message and then exits.
It gives info about the version and then exits.
Here, we will format text from standard input instead of a file in the Linux system using the fmt command as shown below.
$ fmt Hey, welcome to Tutorialspoint... Hey, welcome to Tutorialspoint...
Here, we will format text from a file in the Linux system using the fmt command. First, we need to create a file with unformatted text then we will format it using the fmt command. To create a file, we have to use the cat command as shown below.
$ cat >text.txt Hey, welcome to Tutorialspoint... ^C
Then after, we will format the contents of the file using the fmt command as shown below.
$ fmt text.txt Hey, welcome to Tutorialspoint...
To check more information about the fmt command, we use the --help option with the fmt command in the Linux operating system as shown below.
$ fmt --help
To check version information of the fmt command, we use the --help option with the fmt command in the Linux operating system as shown below.
$ fmt --help
- Display Command Output or File Contents in Column Format in Linux
- How to overwrite a file to hide file contents, and make original contents unrecoverable in Linux?
- How to flushes file system buffers in the Linux operating system?
- How to insert a text at the beginning of a file in Linux?
- How to display the first part of the file in the Linux system?
- How to Create a New Ext4 File System in Linux?
- How to Create a File in the Linux/Unix system using terminal?
- How to display the last part of the file in the Linux system?\n
- How to clear the contents of a Tkinter Text widget?
- How to retrieve the contents of a text field in JavaFX?
- Golang Program to Read the Contents of a File
- How to read the contents of a JSON file using Java?
- How to store the contents of arrays in a file using Java?
- Print contents of a file in C
- How to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)?