Lệnh fmt trong linux

Lệnh fmt trong linux

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áp

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

Tùy chọn

-c, –crown-margin

Duy trì thụt lề của hai dòng đầu tiên.

-p, –prefix = STRING

Chỉ định dạng lại các dòng bắt đầu bằng STRING, gắn lại tiền tố vào các dòng được định dạng lại.

-s, – chỉ có ánh sáng

Chia dòng dài, nhưng không đổ đầy chúng.

-NS,
–tagged-paragraph

Thụt lề của dòng đầu tiên khác với dòng thứ hai.

-u,
– khoảng cách đồng đều

Sử dụng một khoảng trắng giữa các từ, hai khoảng trắng sau câu.

-w, – width = WIDTH

Chiều rộng dòng tối đa (mặc định là 75 cột).

-g, –goal = WIDTH

Chiều rộng mục tiêu (mặc định là 93% chiều rộng).
–Cứu giúp Hiển thị thông báo trợ giúp và thoát.
–phiên bản thông tin phiên bản màn hình và thoát.

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(1) Các câu lệnh FMT(1)

TÊN

fmt - simple optimal text formatter

TÓM TẮT

fmt [-RỘNG] [TÙY_CHỌN]… [TẬP_TIN]…

MÔ TẢ

Đị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.

-c, --crown-margingiữ khoảng thụt dòng của hai dòng đầu tiên-p, --prefix=CHUỖIchỉ định dạng lại những dòng bắt đầu với CHUỖI, gán lại chuỗi tiền tố đó vào dòng đã định dạng lại-s, --split-onlychia những dòng dài, nhưng không điền lại-t, --tagged-paragraphthụt dòng của dòng đầu tiên khác với dòng thứ hai-u, --uniform-spacingmột khoảng trống giữa các từ, hai giữa các câu-w, --width=RỘNGđộ rộng dòng tối đa (mặc định là 75 cột)-g, --goal=RỘNGđộ rộng mục đích (mặc định là bằng 93% of chiều rộng)--helphiển thị trợ giúp này rồi thoát--versionđưa ra thông tin phiên bản rồi thoát

TÁC GIẢ

Viết bởi Ross Paterson.

THÔNG BÁO LỖI

Trợ giúp trực tuyến GNU coreutils: https://www.gnu.org/software/coreutils/
Report any translation bugs to https://translationproject.org/team/

BẢN QUYỀN

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.
Đây là phần mềm tự do: bạn có quyền sửa đổi và phát hành lại nó. KHÔNG CÓ BẢO HÀNH GÌ CẢ, với điều khiển được pháp luật cho phép.

XEM THÊM

Tài liệu đầy đủ có tại: https://www.gnu.org/software/coreutils/fmt
hoặc sẵn có nội bộ thông qua: info '(coreutils) fmt invocation'

DỊCH

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 command

fmt 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

  • -w, – -width=WIDTH option : By default, the maximum width is 75 that fmt command produces in output but with the help of -w option it can be changed, it just requires a numerical value for the width you want to specify.
$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.
  • -t, – -tagged-paragraph option : There can be a need for highlighting the very first line in a text file which can be done by making the indentation of first line different from the other lines which can be done with -t command.
$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.
  • -s option : This option split long lines, but don’t refill them.
$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.
  • -u, – -uniform-spacing option : This option uses one space between words and two spaces after sentences for formatting.
$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. 
  • -c, – -crown-margin option : This option preserves the indentation of the first two lines.
  • -p, – -prefix=STRING option : This option takes a STRING as an argument and reformat only lines beginning with STRING, reattaching the prefix to reformatted lines.
  • -g, – -goal=WIDTH option : This option refers to the goal width i.e default of 93% of width.
  • – -help option : This display a help message and exit.
  • – -version option : This display version information and exit.

Application of fmt command :

  • fmt lets you format the large text files easily with the options like -u which can be very difficult task if done manually.
  • fmt also lets you change the default width with the help of -w option.
  • It is a good way to save time when it comes to format the files.