# LPI Linux Certification/Process Text Streams Using Filters
## Detailed Objective

(LPIC-1 Version 5.0)
Weight: 2
Description:
Candidates should be able to apply filters to text streams.
Key knowledge areas:
* Send text files and output streams through text utility filters to modify the output using standard UNIX commands found in the GNU textutils package.
The following is a partial list of the used files, terms and utilities:
* bzcat
* cat
* cut
* head
* less
* md5sum
* nl
* od
* paste
* sed
* sha256sum
* sha512sum
* sort
* split
* tail
* tr
* uniq
* wc
* xzcat
* zcat

## Pattern matching and wildcards

Wildcards are pattern matching characters commonly used to find file names or text within a file. Common utilizations of a wildcard are: locating file names that you don't fully remember, locating files that have something in common, or performing operations on multiple files rather than individual.
The shell interprets these special characters:
The characters used for wildcard are:
If you use the wildcard characters the shell will try to generate a file from them. Try the following:
Special wildcard characters
Examples:
What about these commands?

## Shell and wildcards

A shell command line can be a simple command or more complex.
The first event in the shell is to interpret wildcards. Only the shell interprets unquoted wildcards.

## Quoting and Comments
#### Quoting

Do quote to prevent the shell interpreting the special characters and to transform multiple words into one shell word.
* 'string' - Nearly everything within the quote is literal:
* "string" - Like 'string', however it interprets $, \, !:
* The backslash (\) treats the following character as literal:
* How could we display the backslash? With the following line:

#### Comments

You can add comments in a command line or a script. Use the character #. A white space must immediately precede #.
Examples:
Commands
* cat, tac: Concatenate files and print on the standard output, from beginning to end or end to beginning, respectively.
* head, tail: Output the first and last part of files.
* nl: Number lines of files.
* wc: Print the number of lines, words, and bytes (in that order) in files.
* cut: Remove sections from each line of files.
* tr: Translate or delete character.
* expand, unexpand: Convert tabs to spaces and space to tabs.
* paste: Merge lines of files.
* join: Join lines of two files on a common field.
* uniq: Remove duplicate lines from a sorted file.
* split: Split a file into pieces.
* fmt: Simple optimal text formatter.
* pr: Convert text files for printing.
* sort: Sort lines of text files.
* od: Dump files in octal and other formats.

## Concatenate files

To concatenate files, use cat.
The results are displayed to the standard output.
Common options:
Examples:
To concatenate files in reverse order, use tac.

## View the beginning and the end of a file

To view only few lines at the beginning or at the end of a file, use head or tail.
The results are displayed to the standard output.
Common options:
Examples:

## Numbering file lines

To add the line number to a file, use nl.
The results are displayed to the standard output.
Common options:
Examples:

## Counting items in a file

To print the number of lines, words and bytes of a file, use wc.
The results are displayed to the standard output.
Common options:
Examples:

## Cutting fields in files

To remove sections from each line of files, use cut.
The results are displayed to the standard output.
Common options:
Examples:
The default delimiter is TAB but can be specified with -d.

## Character conversion

To translate the standard input (stdin) to standard output, use tr.
Common options: -d: delete character in SET1. -s: replace sequence of characters in SET1 by one.
Examples:
To convert tabs to spaces, use expand and to convert spaces to tabs, use unexpand.

## Line manipulation

To paste multiple lines of files, use paste.
Common options:
Examples:
To join multiple lines of files, use join.
To remove duplicated line, use uniq.
Common options:
Examples:
Splitting files
To split big files, use split.
Common options:
Examples:

## Formatting for printing

To format a file, use fmt.
Common options: -w #: maximum line width.
Examples:
To format a file for a printer, use pr.
Common options: -d: double space.
Examples:

## Sort lines of text files

To sort the lines of the named files, use sort.
sort [options] file
The results are displayed to the standard output.
Common options:
Examples:

## Binary file dump

To dump a binary file, use od.
The results are displayed to the standard output and start with an offset address in octal format.
Common options:
Examples:

## Exercises

* Use wildcard characters and list all filenames that contain any character followed by 'in' in the /etc directory.
* Use wildcard characters and list all filenames that start with any character between 'a' and 'e' that have at least two more characters and do not end with a number.
* Use wildcard characters and list all filenames of exactly 4 characters and all filenames starting with an uppercase letter. Do not descend into any directory found.
* Use wildcard characters and list all files that contain 'sh' in /bin.
* Display your environment variable HOME preceded by the string "$HOME value is:"
* Display the contents of $SHELL with two asterisk characters before and after it.
* How would you display the following string of characters as is with echo using double quote and \.
* Compose echo commands to display the following two strings:
** That's what he said!
** 'Never Again!' he replied.
* Display the number of words in all files that begin with the letter 'h' in the /etc directory.
* How would you send a 2M (megabyte) file with two 1.44 M floppy. How would you put back together the split file?
* What is the command to translate the : delimiter in /etc/password by #?
* Exercises results