Piping output to input

Up until now we've been seeing how to direct input and output, but we've been…doing it to files and from files.…So we have to have these files as sort of the intermediary step between them.…What would be great as we could actually take the output from a command and use that…as the input into another command, without having to go to a file in between.…It's something that you are going to use all the time in Unix.…In fact you'll probably use it more often that you will either of those file redirects.…To do it, we use something that we called the pipe.…I'm just going to type one just so you see what it looks like.…

We hold down the Shift key and then the Backslash.…That's the key that is above the Return key.…You get this upright pipe.…So that's what I refer to whenever you hear me say pipe and typically we say we…pipe something into something, right?…We use it as a verb as well.…So if we have something like echo "Hello World", we know that would…normally output to our Terminal, but if instead we use the pipe, we can redirect…

Resume Transcript Auto-Scroll

Author

Released

4/29/2011

Unix for Mac OS X Users unlocks the powerful capabilities of Unix that underlie Mac OS X, teaching how to use command-line syntax to perform common tasks such as file management, data entry, and text manipulation. The course teaches Unix from the ground up, starting with the basics of the command line and graduating to powerful, advanced tools like grep, sed, and xargs. The course shows how to enter commands in Terminal to create, move, copy, and delete files and folders; change file ownership and permissions; view and stop command and application processes; find and edit data within files; and use command-line shortcuts to speed up workflow. Exercise files accompany the course.

Topics include:

Moving around the file system

Creating and reading files

Copying, moving, renaming, and deleting files and directories

Creating hard links and symbolic links

Understanding user identity, file ownership, and sudo

Setting file permissions with alpha and octal notation

Changing the PATH variable

Using the command history

Directing input and output

Configuring the Unix working environment

Searching and replacing using grep and regular expressions

Manipulating text with tr, sed, and cut

Integrating with the Finder, Spotlight, and AppleScript

Skill Level Beginner

6h 35m

Duration

2,053,799

Views

Show MoreShow Less

Q: The exercise files for the following movies appear to be broken:
07_02_files
07_03_files
07_04_files
07_05_files
08_03_files

Is there something wrong with them?

These exercises include one or more "dot files", whose file names start with a period. These files are normally hidden from view by the Finder. So that they would show up in the Finder, the period has been removed from the file names. Additionally, "_example" has been added at the end of the file name to make it clear that the file will not work as-is.
To make the dot files usable, either:

1) Open the file in a text editor to view its contents. Note that it may not be possible to double-click the file to open it because there is no file extension (such as .txt).
2) Resave the file under a new name (usually by choosing File > Save As), adding a "." to the beginning of the file name and removing "_example" from the end.

OR

1) Copy and rename the file from the Unix command line using the techniques discussed in this course. Rename the file by adding a "." to the start and removing "_example" from the end. Include the "-i" option to prevent overwriting an existing file unexpectedly.
Example: cp -i ~/Desktop/Exercise\ Files/Chapter_07/07_02_files/bashrc_example ~/.bashrc

The instructor uses the UNIX program 'units' to convert 72° Fahrenheit to degrees Celsius. The returned value of 40 is incorrect. The correct result should be 22°C. What's the reason for this discrepancy?

The problem is that units does the 5/9 calculation but does not have the ability to subtract 32. So you'll need to subtract (or add) the 32 degrees yourself.