Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI The UNIX System Shell Data Handling: Redirection and Piping

Similar presentations


Presentation on theme: "CSCI The UNIX System Shell Data Handling: Redirection and Piping"— Presentation transcript:

1 CSCI 330 - The UNIX System Shell Data Handling: Redirection and Piping
NIU - Department of Computer Science

2 Output The output statement of the shell is the “echo” command
The C Shell Output The output statement of the shell is the “echo” command Syntax: echo [option] arg1 arg2 …argN its arguments can be strings or variables option “-n” will suppress trailing newline CSCI The UNIX System Copyright Department of Computer Science, Northern Illinois University, 2005

3 Output with echo Examples: % echo “Hello Ray" Hello Ray
The C Shell Output with echo Examples: % echo “Hello Ray" Hello Ray % echo “Hello $USER" Hello a132436 % echo “It is now `date`” It is now Mon Feb 25 10:24:08 CST 2008 CSCI The UNIX System Copyright Department of Computer Science, Northern Illinois University, 2005

4 Output Redirection (>)
The C Shell Output Redirection (>) Syntax: command > file Sends output of command to file, instead of to terminal Examples: % du > status % (date; du) > status Calls the disk usage command for the current directory and redirects the output to a file called ‘status’ CSCI The UNIX System ( ) indicates command groups. Use it to combine the output of multiple commands. In this example, we place time and date in front of the disk usage Copyright Department of Computer Science, Northern Illinois University, 2005

5 Input Redirection (<)
The C Shell Input Redirection (<) Syntax: Command < file Command will read (take input) from file, instead of from terminal Example: % tr “[A-Z]” “[a-z]” < report.input CSCI The UNIX System Copyright Department of Computer Science, Northern Illinois University, 2005

6 Examples: Output / Input
The C Shell Examples: Output / Input Redirecting input and output: % tr ‘[A-Z]’ ‘[a-z]’ < r.in > r.out Output of command becomes input to next: % ls > temp.txt; wc < temp.txt Eliminate the middleman: pipe % ls | wc CSCI The UNIX System Copyright Department of Computer Science, Northern Illinois University, 2005

7 Appending Output Syntax: command >> file
The C Shell Appending Output Syntax: command >> file adds output of command at the end of file If file does not exist, shell creates it Examples: % date > usage-status % ls -l >> usage-status % du -s >> usage-status Build the file ‘usage-status’ from the output of the ‘date’, ‘ls’, and ‘du’ commands CSCI The UNIX System Copyright Department of Computer Science, Northern Illinois University, 2005

8 Summary: Redirections and Pipe
The C Shell Summary: Redirections and Pipe Command Syntax Meaning command < file Redirect input from file to command command > file Redirect output from command to file command >> file Redirect output of command and appends it to file command1 | command2 Take/pipe output of command1 as input to command2 CSCI The UNIX System Copyright Department of Computer Science, Northern Illinois University, 2005


Download ppt "CSCI The UNIX System Shell Data Handling: Redirection and Piping"

Similar presentations


Ads by Google