|


| NAVIGATION |
|
Home |
|
Store |
|
|
| INSIDE MAC |
|
Television Shows |
|
Broadcast Shows |
|
Daily News Shows |
|
Special Shows |
|
|
| EVENTS |
|
|
|
|
|
|
|
|
| DAILY TIPS |
|
Design |
|
Mac OS X |
|
Mac OS X UNIX |
|
|
| COMMUNITY |
|
Surveys |
|
|
| NEWS |
|
Current |
|
Press |
|
Archive |
|
|
| FEATURES |
|
Editorial |
|
Dr. Mac |
|
Reviews |
|
Reader Reports |
|
|
| RESOURCES |
|
FAQ |
|
Documentation |
|
Learning Center |
|
MAN pages |
|
Glossary |
|
Tutorials |
|
Tips |
|
Links |
|
|
|

|
|
|
OSXFAQ Mac OS X UNIX Tip-of-the-Day
Scripting One-Liners - Batch Process Files
Here's a handy way to process every file in a directory:
$ for f in *; do echo "File: $f"; done
File: a file with spaces.txt
File: db-snmpd.conf
File: snmp.conf
File: snmp.txt
File: snmpd.conf
File: treewalk-dot
$
(A more useful example would do something more than simply echo each filename.) It'll even cope with filenames that contain spaces, as witnessed by the first file in the list.
You can process each field in a file with:
$ for f in $(cat file-to-process); do echo $f; done
Visit the Site of the Book of the Unix Tips:
Projects 58 and 83 cover the batch-processing of files using both Bash functions and Bash shell scripts.
Discuss this trick in the
OSXFAQ Learning Center forum
E-mail your comments or suggestions to
webmaster@osxfaq.com
|


|
Copyright © 2000-2010 Inside Mac Media, Inc. All rights reserved. |
Apple assumes no responsibility with regard to the selection, performance, or use of the products or services. All understandings, agreements, or warranties, if any, take place directly between the vendors and prospective users. |
| Apple, the Apple logo, Mac, PowerMac G4, PowerMac G5, Xserve, Xserve RAID, PowerBook, iBook, Airport, AirPort Extreme, iMac, eMac, iLife, iMovie, iCal, iPhoto, iTunes, QuickTime, FireWire, iPod, iSight, AppleWorks, Macintosh, Jaguar, Panther, Mac OS, Mac OS X and Mac OS X Server are trademarks of Apple Computer, Inc. |
|