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


August 01, 2001

Shell Scripting 101, Lesson 8

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

You’re not limited to keeping the tokens in the order in which they appear in the input file. You can, for example, display the tokens in reverse order with the command

For /f "tokens=1,2,3,4,5,6,7,8,9,10" %i in (C:\testdata.txt)
 Do Echo %r %q %p %o %n %m %l %k %j %i

You can even display the tokens in a comma-separated format with a command such as

For /f "tokens=1,2,3,4,5,6,7,8,9,10" %i in (C:\testdata.txt)
Do Echo %i,%j,%k,%l,%m,%n,%o,%p,%q,%r

As I discussed in "Shell Scripting 101, Lesson 4," you can redirect the For /f command’s output to a file by adding the >> redirection symbol:

For /f "tokens=1,2,3,4,5,6,7,8,9,10" %i in (C:\testdata.txt) Do Echo
%i,%j,%k,%l,%m,%n,%o,%p,%q,%r>>C:\testreport1.txt

Experimenting with the delims Option
In the command-shell window, run the command

Echo 10,100,55,23 > C:\testdata2.txt

to create the file testdata2.txt on your C drive. Now, run the commands

For /f "tokens=1,2,3,4" %i in (C:\testdata2.txt) Do Echo %i %j %k %l For /f "tokens=1,2,3,4 delims=," %i in (C:\testdata2.txt) Do Echo %i %j %k %l

   Previous  1  2  3  [4]  5  Next 


Top Viewed ArticlesView all articles
Microsoft, News Corp. Discuss Locking Out Google

Microsoft and Rupert Murdoch's News Corp. recently discussed an alliance that would counter Google's fledgling online news service. ...

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. ...

Command Prompt Tricks

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


Related Articles Programmatically Change Permissions in Print Clusters

Shell Scripting 101, Lesson 10

Shell Scripting 101, Lesson 9

Shell Scripting 101, Lesson 7

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

Related Events 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