The PIPE Character and Filters

The pipe character is another symbol used to manipulate the input and output of commands. The pipe character ( | ) takes the output of one command and forces that output into a second DOS command.

The pipe character is normally used with 3 DOS commands called filters, it can however, be used with any command that produces output, The 3 DOS filters are, MORE, and FIND SORT

More

Accepts information from a command and displays the information one screen at a time.

  1. dir | more
  2. more < dirlist
  3. type dirlist | more

Both syntax forms of 2 and 3 work identically.

Don’t use more alone it requires input to redirect or to pipe.

Find

Searches the specified files, for any lines of text that contain the specified string.

/V

Displays all lines not containing the specified string.

/C

Displays only a count of the lines that contain the specified string.

/N

Precedes each line with the file’s line number

/I

Specifies that the search is not to be case-sensitive.

find "Error" output.txt

find "Error" output.txt /c

find "Area Code: 206" phone.txt addr.txt

searches the addr.txt file in addition to the phone.txt

find "Area Code: 206" phone.txt > nwest.num

 

Sort

The sort command, is a filter (we’ll talk more about filters in a while), it sorts, or arranges lines of data in alphabetical order.

Switches

/R

Reverses the order of the sorting operation; that is it sorts form Z to A, and then from 9 to 0

/+N

Sorts the file according to the character in column N (number). If you do not use this switch the sort command sorts data according to the characters in column 1

If you type SORT at the prompt and press enter, DOS waits for you to enter in data to sort. If you were to enter in the following:

VODKA

GIN

WHISKEY

SCOTCH

and press Ctrl-Z and then press enter. The sort command would display the sorted list on the screen.

GIN

SCOTCH

WHISKEY

VODKA

The following sort command takes its input from a file named list.txt instead of the keyboard.

sort < list.txt

The following command sorts the file and save its sorted output to a file named SORTFRT.TXT. Use one command.

sort < list.txt > sorted.txt

Format

sort /r < expenses.txt

Unsorted Testfile.txt

1234

5678

bbbb

eeee

gggg

yyyy

tttt

aaaa

eeee

iiii

rrrr

bbbb

uuuu

xxxx

sort < testfile.txt

Sorted Testfile.txt

1234

5678

bbbb

eeee

eeee

iiii

gggg

yyyy

rrrr

bbbb

tttt

aaaa

uuuu

xxxx

sort /+5 < TestFile

Sorted Testfile.txt

1234

5678

tttt

aaaa

rrrr

bbbb

bbbb

eeee

eeee

iiii

uuuu

xxxx

gggg

yyyy

Limitations

Doesn’t work with files larger than 64k

Doesn’t distinguish between uppercase or lowercase.

Off-set values for sorting directory listings

Off-Set Value

Sorting by

1

Root Name

10

File Extension

14

File Size

24

File Date

34

File Time

 

 

Examples

dir | sort /+14

Pipes the output of the dir command to the sort filter, Sort then sorts the directory listing starting with column 14 (file size)

dir | sort /+14 | more

Pipes the output of the dir command to the sort filter, Sort then sorts the directory listing starting with column 14 (file size). The output of the sort is then piped to the more command.