- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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.
Syntax
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 |
---|---|
1 | -c, --crown-margin Preserve the indentation of the first two lines |
2 | -p, --prefix=STRING Reformat beginning lines with specified STRING, reattaching the prefix to reformatted lines. |
3 | -s, --split-only Split only long lines, but don’t refill |
4 | -t, --tagged-paragraph Indentation of first-line different from second |
5 | -u, --uniform-spacing 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) |
8 | --help Displays a help message and then exits. |
9 | --version 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
- Related Articles
- 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?
- Python - Display the Contents of a Text File in Reverse Order?
- 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 first part of the file in the Linux system?
- How to display the last part of the file in the Linux system?
- How to replace string in a large one line, text file in Linux?
- How to retrieve the contents of a text field in JavaFX?
- How to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)?
- How to clear the contents of a Tkinter Text widget?
- How to store the contents of arrays in a file using Java?
- How to read the contents of a JSON file using Java?
