Lệnh fmt trong linux
Show Trên các hệ điều hành giống Unix, lệnh fmt là một định dạng để đơn giản hóa và tối ưu hóa các tệp văn bản. Trang này bao gồm phiên bản GNU \/Linux của fmt. Sự miêu tảfmt định dạng lại từng đoạn trong (các) FILE được chỉ định, ghi vào đầu ra chuẩn. Tùy chọn -WIDTH là dạng viết tắt của – width = DIGITS. Cú phápfmt [-WIDTH] [OPTION]... [FILE]... Tùy chọn
Nếu không có FILE nào được chỉ định hoặc nếu FILE là một dấu gạch ngang (“-“), fmt sẽ đọc từ đầu vào chuẩn. Các ví dụfmt myfile.txt Hiển thị phiên bản định dạng lại của tệp myfile.txt. fmt < myfile.txt > myfile2.txt Định dạng lại myfile.txt và ghi đầu ra vào tệp myfile2.txt. nroff – Định dạng tài liệu cho màn hình đầu cuối hoặc máy in dòng. fmt - simple optimal text formatter fmt [-RỘNG] [TÙY_CHỌN]… [TẬP_TIN]… Định dạng lại mỗi đoạn văn trong (các) TẬP_TIN, ghi ra đầu ra tiêu chuẩn. Tùy chọn
-RỘNG là dạng viết tắt của tùy chọn --width=CHỮ_SỐ. Không chỉ ra TẬP_TIN, hoặc khi TẬP_TIN là “-”, thì đọc từ đầu vào tiêu chuẩn. Tùy chọn dài yêu cầu đối số thì tùy chọn ngắn cũng vậy. Viết bởi Ross Paterson. Trợ giúp trực tuyến GNU coreutils: https://www.gnu.org/software/coreutils/ Copyright © 2022 Free Software Foundation, Inc. Giấy phép GPL pb3+ : Giấy phép Công cộng GNU phiên bản 3 hay sau https://gnu.org/licenses/gpl.html. Tài liệu đầy đủ có tại: https://www.gnu.org/software/coreutils/fmt Bản dịch tiếng Việt của trang hướng dẫn này do thực hiện. Bản dịch này là Tài liệu Miễn phí; đọc Giấy phép Công cộng GNU Phiên bản 3 hoặc mới hơn để biết các điều khoản bản quyền. Chúng tôi cho rằng KHÔNG CÓ TRÁCH NHIỆM PHÁP LÝ. Nếu bạn tìm thấy một số sai sót trong bản dịch của trang hướng dẫn này, vui lòng gửi thư đến TODO. 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 $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 commandfmt by default with no option used format all the words present in the given file in a single line. $ cat kt.txt hello everyone. Have a nice day. /* fmt by default puts all words in a single line and prints on stdout. */ $fmt kt.txt hello everyone. Have a nice day. To save or write the formatted output you can use fmt as : /* Here the formatted output gets written in dv.txt */ $fmt kt.txt > dv.txt Options for fmt command
$cat kt.txt hello everyone. Have a nice day. /* the width gets reduced to 10 with -e option */ $fmt -w 10 kt.txt hello ever yone. Have a nice day.
$cat kt.txt hello everyone. Have a nice and prosperous day. /*-t makes the indentation of first line different from others */ $fmt -t kt.txt hello everyone. Have a nice and prosperous day.
$cat kt.txt Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It is not rude, it is not self-seeking, it is not easily angered, it keeps no record of wrongs. Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres. Love never fails. /* long lines get splitted with -s option */ $fmt -s kt.txt Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It is not rude, it is not self-seeking, it is not easily angered, it keeps no record of wrongs. Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres. Love never fails.
$cat kt.txt Love is patient, love is kind. It does not envy, it does not boast, it is not proud. /* Spaces are uniformed with -u option */ $fmt -u kt.txt Love is patient, love is kind. It does not envy, it does not boast, it is not proud.
Application of fmt command :
|