KandZ – Tuts

We like to help…!

Linux CLI 48 🐧 nl, fold and fmt commands

a - nl command
nl command is used to number lines of text lines
It is useful when referencing or citing specific lines in a document
common options: -b a β†’ number all lines, default -b t β†’ number non blank lines, -n ln|rz|rn β†’ sets specified format -i # β†’overrides default incremetn
nl filename.txt β†’numbers lines
nl -n rz filename.txt β†’ numbers lines and sets right alignment and fills with zeros
nl -n ln filename.txt β†’ numbers lines and sets left alignment
nl -n rn filename.txt β†’numbers lines and sets right alignment
nl -i 2 filename.txt β†’ numbers lines but increments by 2

b - fold command
fold command wraps input text into a specified width
It is useful for formatting long lines of text into readable paragraphs
common commands: -w# β†’ specifies the length(n) of the line
-s β†’ breaks lines on spaces
fold longtext.txt β†’ wraps the text on default length
fold -w20 longtext.txt β†’ specifies the line length to 20
fold -s longtext.txt β†’ breaks the lines on space

c - fmt command
fmt command formats text paragraphs
It automatically adjusts the length of lines to fit within width margins
Default length is 75 characters
common options: -w β†’ specifies the line length
-c β†’ paragraphs have consistent line length by breaking them at a natural stopping point
fmt format.txt β†’ formats the text at 75 characters long
fmt -w20 format.txt β†’ specifies the line length to 20
fmt -w20 -c format.txt β†’ specifies the length and breaks them at a natural stopping point

Leave a Reply