From the Gloucester Linux User Group Website http://www.gloucs.lug.org.uk

4. Working with Grep and Sed

Using regular expressions

"A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions, by using various operators to combine smaller expressions."

From the grep manpage.

Describe here the main points to remember when using regular expressions. (...much to do here)

Online Notes

Grep

You need to know the difference in opperation between grep, egrep and fgrep. (...much to do here)

grep
"Search one or more files for lines that match a regular expression pattern. Exit status is 0 if any lines match, 1 if none match, and 2 for errors." (O'Reilly definition)
Also have a look at the www.linuxnewbie.org guide on the subject and the Mandrake Guide.
egrep
"Search one or more files for lines that match an extended regular expression regexp. egrep doesn't support the regular expressions (, ), n, <, >, {, or } but does support the other expressions, as well as the extended set +, ?, |, and ( ). Remember to enclose these characters in quotes. Exit status is 0 if any lines match, 1 if none match, and 2 for errors." (O'Reilly definition)
fgrep
"Search one or more files for lines that match a literal text string pattern. Exit status is 0 if any lines match, 1 if not, and 2 for errors." (O'Reilly definition)
Books
Grep : Searching for a Pattern
Alain Magloire, Iuniverse.Com, Aug 2000
Avalible at Amazon
Tutorials

Sed

"Sed stands for Stream EDitor. Sed is a non-interactive editor, written by the late Lee E. McMahon in 1973 or 1974. A brief history of sed's origins may be found in an early history of the Unix tools, at http://www.columbia.edu/~rh120/ch106.x09."

"Instead of the user altering a file interactively by moving the cursor on the screen (like with Word Perfect), the user sends a script of editing instructions to sed, plus the name of the file to edit (or the text to be edited may come as output from a pipe). In this sense, sed works like a filter -- deleting, inserting and changing characters, words, and lines of text. Its range of activity goes from small, simple changes to very complex ones."
From the SED FAQ at http://www.ptug.org/sed/sedfaq.htm
Books
Sed and Awk
Dale Dougherty, Arnold Robbins, Nov 1996 O'Reilly
Avalible at Amazon
Sed and Awk Pocket Reference
Arnold Robbins, Jun 2002 O'Reilly
Avalible at Amazon
Tutorials

To do: Comment on each, describe regular experssions. Describe Sed.

SourceForge LogoWant to suggest improvements, resources, contribute or comment on this article? Please do.