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

Wednesday - Commands to Compare Text Files

split ... split a file into many files
Split a large file into many small files each 1000 lines long
Option -l to specify a different number of lines for the small files

sort ... sort the lines of a file into alphabetic order
Each line is considered a number of columns, so you can sort on any column, or key
Option -t to specify the key separator (space, command, tab, etc)
Option -k to specify which key/column to sort on
Option -b to ignore leading blanks
Option -f to fold case (make the sort case insensitive)
...and more....

uniq ... filter out repeated lines of a file
The file must be sorted first
For repeated lines only the first copy is written out
Option '-f fields' to ignore the first 'fields' fields of each line in the comparison
Option '-s chars' to ignore the first 'chars' characters of each line in the comparison
Option -c to precede each output line with the number of repetitions in the original input

join ... perform a database join on files
Specify a field (as for 'sort') by which the files are compared
A line is displayed for each pair of lines in the two files where the compared fields match

paste ... merge corresponding lines of two file

comm ... display lines common to two files
The two files must be sorted first
Three columns are produces for lines that are in file one only, file 2 only, and both files
Options -1, -2, -3 to suppress printing of their respective columns

diff ... compare two files
Compare two files and print the differences in terms of small differences in lines, new lines, deleted lines
Use to compare two versions of the same file
Option -b to ignore differences in white space
Option -B to ignore differences in blank lines
Option -i to ignore changes in case

diff3 ... compares three files
Comparison between three files f1, orig, and f2 compares the differences between f1 and f2 relative to orig
Option -A to incorporate all the changes between orig and f2 into f1 - this acts like a merge operation to merge the changes made to f2 (relative to orig) into f1

sdiff ... compare and merge two files
Compare the differences between two files and merge them to a third file
Option -b to ignore differences in white space
Option -B to ignore differences in blank lines
Option -i to ignore changes in case

(See tips weeks 26 and 35)

zdiff, bzdiff ... diff zipped, bzipped files


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