Given its heritage in Unix, it's no surprise that GNU has a wealth of text processing tools and techniques to aid coders, writers, and publishers in editing and otherwise manipulating text documents.
This three-part series will introduce the bulk of those tools and utilities (plus some techniques) and include links to learning more. This part (part 1B) will cover more of the basic tools. The previous section -- GNU text processing overview, part 1A: The basics -- introduced other basic commands.
To learn the basic functions of any of the commands below, type the name of the command followed by "--help". For example, to learn more about the "less" command, you would type (at the command prompt):
$ less --help
(Don't type the dollar sign "$", that simply represents the user command prompt.)
Also, if you need more detailed information about any of the following commands you can read their "man" or "info" pages by typing the word "man" or "info" respectively, followed by the command name. To see either manual for the "less" command type:
$ man less
$ info less
The "uniq" utility is used mainly to elminate duplicate lines in a file. It parses a file (or files) finds lines that are redundant and prints only one of them (to stdout or a file, using redirection). For example:
$ uniq name-of-text-file
To learn more about uniq:
The cut command will cut and print specific "fields" from a text file. By default, it uses the space character as a delimeter (this can be changed) and defines all characters between spaces as a field. It will then cut and print that field from the file. For instance, if you wanted to print a list of users and their default shells on a given system, you could have cut parse the /etc/passwd file and print the first and seventh fields, like this:
$ cut -d: -f1,7 /etc/passwd
This tells "cut" to use the colon ":" character as a delimiter and to print the first field (the user name) and the seventh (which contains the default shell) for every user listed in the passwd file.
To learn more about cut:
- The cut Command
- Invoking cut
- The cut Program
- cut Man Page
- 10 Practical Linux Cut Command Examples to Select File Columns
- Examples of the cut Command
The paste command will print the lines of given text documents sequentially separated by a tab. For example, if you wanted to see the respective lines of two text files listed on the same line, separated by a tab, you would type:
$ paste file1 file2
To learn more about paste:
The basic function of grep is to find and print lines of text in a document that contain a given text string. For instance, if you wanted to see only the information for the root user in your system's passwd file you would type:
$ grep root /etc/passwd
To learn more about grep:
Copyright © 2013 Russell James
Permission is granted to copy, distribute and/or modify this document under the terms of the Creative Commons Attribution-ShareAlike 3.0 Unported license.