PIPES, FILTERS, AND REDIRECTION Additional Adds by David Sims.

22
PIPES, FILTERS, AND REDIRECTION Additional Adds by David Sims

Transcript of PIPES, FILTERS, AND REDIRECTION Additional Adds by David Sims.

PIPES, FILTERS, AND REDIRECTION

Additional Adds by David Sims

Redirection of Standard I/O (Input/Output)

CTEC 110Pipes, Filters & Redirection (22 slides) 2

Redirection of Standard I/O (Input/Output)

CTEC 110Pipes, Filters & Redirection (22 slides) 3

Redirection of Standard I/O (Input/Output)

• Not all Commands deal with standard Input and Output

• Symbols used for redirection:> (Greater Than)< (Less Than)>> (Double Greater Than)

CTEC 110Pipes, Filters & Redirection (22 slides) 4

Redirection

• Can redirect both Input and Output of filter commands

• Some of the most common filter commands are:– SORT– MORE– FIND

CTEC 110Pipes, Filters & Redirection (22 slides) 5

Piping Standard output of one program is used as

standard input to next program Used with filter commands to further refine

data Not limited to two programs. Can use

several pipes on one line.

CTEC 110Pipes, Filters & Redirection (22 slides) 6

Combining Commands with Pipes and Filters

• A command must be on either side of pipe• Output of one command is input of the other

• Redirection is different and should not be confused with piping

CTEC 110Pipes, Filters & Redirection (22 slides) 7

Using SORT

CTEC 110Pipes, Filters & Redirection (22 slides) 8

Using SORT

Open up a Command Prompt and change to Z:\CTEC110\MyScriptsTry the following:

1. SORT MERCURYVENUSEARTH3MARSJUPITERPress F6 function key

Results should be similar to previous slide!

CTEC 110Pipes, Filters & Redirection (22 slides) 9

2.SORT333323124 Press F6 function key

What kind of results did you get?Was it as expected?

CTEC 110Pipes, Filters & Redirection (22 slides) 10

Using SORT

3.SORT333##3#23124 Press F6 function key

What results did you get here?Is it what was expected?

CTEC 110Pipes, Filters & Redirection (22 slides) 11

Using SORT

SORT Command with RedirectionTry these out (Copy PERSONAL.FIL and STATE.CAP to MyScripts)…You will use the “Command Prompt” for the following…Copy from the MyScriptsBook directory to MyScripts directory on the Z-Drive!

1.COPY Z:\CTEC110\MyScriptsBook\STATE.CAP2.SORT < STATE.CAP3.SORT STATE.CAP4.SORT /R < STATE.CAP5.SORT /+17 STATE.CAP…

CTEC 110Pipes, Filters & Redirection (22 slides) 12

SORT Command with Redirection

6.SORT /+17 STATE.CAP > SORTED.CAP7.TYPE SORTED.CAP8.SORT /+17 STATE.CAP /O BYCITY.CAP9.TYPE SORTED.CAP10.TYPE BYCITY.CAP

CTEC 110Pipes, Filters & Redirection (22 slides) 13

Using the MORE FilterTry the following:Remember! COPY Z:\CTEC110\MyScriptsBook\PERSONAL.FIL

1.DIR C:\WINDOWS | MORE2.Press Enter until back at system prompt3.DIR C:\WINDOWS | MORE4.Press the Space Bar5.DIR C:\WINDOWS | MORE6.Q…

CTEC 110Pipes, Filters & Redirection (22 slides) 14

Using the MORE Filter

7.DIR C:\WINDOWS | SORT /+39 | MORE8.Press Space Bar until end and then Q9.MORE PERSONAL.FIL10.Press Space Bar until end and then Q11.TYPE PERSONAL.FIL | MORE12.Press Space Bar until end and then Q…

CTEC 110Pipes, Filters & Redirection (22 slides) 15

Using the MORE Filter

13.MORE PERSONAL.FIL /C +2014.MORE SORTED.CAP BYCITY.CAP /C15.Press the Space Bar16.MORE SORTED.CAP BYCITY.CAP17.Press the Space Bar18.Close all open windows and return to

desktop environment, the GUI

CTEC 110Pipes, Filters & Redirection (22 slides) 16

Extended Features of MORE

Try the following:1. Click Start/Run2. Type in only CMD.EXE /X3. Click OK4. CD /d Z:\CTEC110\MyScripts5. MORE PERSONAL.FIL6. Press Enter twice7. Press Q…

CTEC 110Pipes, Filters & Redirection (22 slides) 17

Extended Features of MORE

8.MORE PERSONAL.FIL9.Key in P10.Key in 5 <CR>11.Press the = sign12.Press S13.Key in 3Leave the command prompt open…

CTEC 110Pipes, Filters & Redirection (22 slides) 18

Using the FIND Filter

Try the following:1.CLS2.FIND “Smith” PERSONAL.FIL3.FIND /V “Smith” PERSONAL.FIL4.FIND /N “Smith” PERSONAL.FIL5.FIND /C “Smith” PERSONAL.FIL6.FIND /I “Jones” PERSONAL.FIL7.FIND “Jones” PERSONAL.FIL /I

CTEC 110Pipes, Filters & Redirection (22 slides) 19

Combining Commands1. FIND “Teacher” PERSONAL.FIL | FIND “CA”2. FIND “Teacher” PERSONAL.FIL | FIND “CA” >

TEACHER.FIL3. TYPE TEACHER.FIL4. FIND “PrOfeSSor” PERSONAL.FIL | FIND “AZ” |

SORT5. Press the up arrow key once6. Use the left arrow-move to P in PERSONAL.FIL…

CTEC 110Pipes, Filters & Redirection (22 slides) 20

Combining Commands

7.Key in /I <SPACE> uppercase letter (i)8.Press the End key9.Press Enter10.DIR C:\WINDOWS | SORT /+39 | MORE11.Press Space Bar until end and then Q12.DIR C:\WINDOWS | FIND “<DIR>” |

SORT /+39

CTEC 110Pipes, Filters & Redirection (22 slides) 21

END OF

PIPES, FILTERS, AND REDIRECTION