DirectNET

Data Center Management Solutions including UPS Systems, Data Center Cooling, KVM over IP & IP Power Strips, Server Racks and Server Rack accessories; KVM Switches and KVM Extenders; Rackmount Monitors and Rackmount Keyboards.


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

OUR PARTNERS

OSXFAQ Mac OS X UNIX Tip-of-the-Day   back to index

Week 101 - Unix Commands Reference (7 March 2005)

by Adrian Mayo - Editor, OSXFAQ

Friday - Commands to Change File Content

awk ... pattern scanning and manipulation language
Awk reads a text file line by line and applies a series of search, replace, and edit operations to lines that match given criteria.
Awk can read a script file for its processing commands
the language combines a 'C'-like programming language with regular expression search and replace.
(See tips weeks 86 and 87)

gawk, nawk ... variations of awk
Not available in the standard Mac OS X install

sed ... stream editor
Sed reads a text file line by line and applies a series of search, replace, and edit operations to lines that match given criteria
Sed can read a script file for its processing commands
the language uses regular expression search and replace functionality, but lacks the 'C'-like programming language.
(See tips weeks 85 and 89)

tr ... translate on character into another
Reads a text file and translates all occurrences of a given character into another
By default reads and writes standard in and out, so redirection is necessary to work on files
Don't write the output back to the input file, otherwise it will end up empty

col ... strip chars
Col can be used to clean-up files
Option -b to remove multiple backspaces as output by the man pages
Option -x to convert tabs characters to multiple spaces

(See tips week 10)

cut ... filters columns from files
Cut can process a file that has columns of text (for example tab-separated tables) and extract just the specified columns
Option -f to list the columns to be output, like '-f 3,5' for 3 and 5, '-f 3-5' for 3 to 5, or '-f 1,3-5' for 1 and 3 to 5.
Option -d to specify the field separator (by default tab), like '-d " "' for space, or '-d ","' for comma

expand ... expand tabs to spaces

unexpand ... compress spaces to tabs

fmt ... format a text file
Read a file and write a version who's lines do not exceed a maximum specified length, or optionally do not come in under a minimum specified length
Option -c to centre text
Option -p to allow indented paragraphs
Option -s to collapse multiple white space inside lines

fold ... fold long lines
Simple version of fmt which breaks long lines to 80 characters or less
Option -w to specify a maximum width other than 80


Discuss this trick in the Learning Center forum


If you want to learn more about Mac OS X Unix visit the Learning Center  click.

  • For beginners: Mac OS X Unix Tutorials
  • For detailed information on specific topics: Advanced Unix
  • For OS X in gereral: Mac OS X Tutorials

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.