nroff
nroff is a text formatting tool used to format documents for display on terminals and line printers. nroff is particularly useful for creating man pages and other text-based documentation in Unix-like systems. It’s part of the groff document processing system on modern Linux systems. Here’s how to get started with nroff:
Basic Usage
- Create a text file with nroff formatting commands, typically ending in .1 or .ms extension.
- Use the nroff command to process the file:
$ nroff -ms myfile.ms > output.txt
This processes myfile.ms using the -ms macro package and outputs the formatted text to output.txt.
Key Formatting Commands
nroff uses dot commands that start with a period (.) to control formatting:
- .TL – Title
- .AU – Author
- .SH – Section Header
- .PP – Paragraph
- .LP – Left-aligned Paragraph
- .sp – Insert vertical space
- .br – Line break
Text Styling
- \fB – Bold text
- \fI – Italic text
- \fR – Return to regular text
Example:
This is \fBbold\fR and this is \fIitalic\fR text.
Macro Packages
nroff supports various macro packages for different document types:
- -ms: General-purpose macros
- -man: For manual pages
- -me: Another general-purpose set
Example Document
.TL
My First nroff Document
.AU
John Doe
.SH
Introduction
.PP
This is a paragraph in my nroff document. It demonstrates basic formatting.
.SH
Conclusion
.PP
nroff is a powerful tool for formatting text documents in Linux.
Processing and Viewing
Process the file:
$ nroff -ms mydoc.ms > mydoc.txt
View the output:
$ less mydoc.txt
That’s it for this chapter 13, text processing in Linux ! You’ve now learned how to use text processing tools to manipulate and analyze text files. In the next chapter, we’ll dive into networking—using commands like ping, curl, and wget to interact with networks and the web. Until then, practice these tools to become more comfortable with text processing.