Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


June 28, 2001

Shell Scripting 101, Lesson 7

RSS
Subscribe to Windows IT Pro | See More Windows NT 4.0 Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

You can easily join commands with command symbols. You can use four symbols: pipe (|), ampersand (&), double ampersand (&&), and double pipe (||).

The | Symbol
The | symbol pipes the output from one command (Command A) to another command (Command B). You place the | symbol between the commands:

Command A | Command B

You often have to filter a command’s output before using it. Thus, you’ll probably use the | symbol often to pipe output to the Find command. The Find command searches a command’s output (or text from an input file) for the string you specify. The Find command displays any line that contains the string and discards all the other lines.

For example, suppose you want to know when the C:\winnt directory was created. As I discussed in "Shell Scripting 101, Lesson 2," the Dir command lists information, including creation date and time, about the subdirectories and files in the specified drive or directory. In this case, you use the command

Dir /ad C:\

The /a switch followed by the letter d specifies that you want to list only directories on the C drive.

You now have the information you want, so you just need to pipe it to the Find command to filter out the information you don’t want. As the command

Dir /ad C:\ | Find /i "winnt"

shows, you use the | symbol to pipe the Dir command’s output to the Find command and specify "winnt" as the string for which to search. You need to enclose the string in quotes. The /i switch after Find makes the search case insensitive. As Figure 1 shows, when you run this command, you receive just the line that contains information about the \winnt directory.

   Previous  [1]  2  Next 


Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...


Related Articles Shell Scripting 101, Lesson 10

Shell Scripting 101, Lesson 9

Shell Scripting 101, Lesson 8

Shell Scripting 101, Lesson 6

Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

Windows, Unix, Linux Interoperability

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement