Main index

Introducing UNIX and Linux


Overview
Using filters
      Collating sequence
      Character classes
Character-to-character transformation
Selecting lines by content
      Regular expressions
      Basic regular expressions
      Extended regular expressions
      Grep
Stream editor
      Sed addresses
Splitting a file according to context
Choosing between the three filters
More on Vi
Summary
Exercises

Choosing between the three filters

It will be apparent that anything Grep or tr can do, Sed can also do (though possibly not as elegantly). Why do we need Grep and tr? First of all, it is good practice to use the simplest filter available to you, if a choice exists.

Speed may be important if the data you wish to filter is large, or your UNIX system is small and not very powerful. Since Sed does more than the other two utilities, it is almost certainly slower. Unless you really need the facilities offered by Sed, then it will be easier to remember how to use the other two utilities. Extended regular expressions are only available to Grep. Finally, some operations are not easy to perform using Sed - try coding the following using only Sed:

tr A-Z a-z
grep -l abc *



Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck