Shell Scripting Notes – Apple Primer

Shell scripting primer from Apple:

http://developer.apple.com/mac/library/documentation/opensource/conceptual/shellscripting/Introduction/Introduction.html

poem.txt
foo.txt

Samples:

You can use regular expressions to search for strings in a file or a block of text by using the grep command. For example, to look for the word “bar” in the file foo.txt, you might do this:

grep "bar" foo.txt # or cat foo.txt | grep "bar"

Positional anchors allow you to specify the position within a line of text where an expression is allowed to match. There are two positional anchors that are regularly used: caret (^) and dollar ($). When placed at the beginning or end of an expression, these match the beginning and end of a line of text, respectively.

For example:

# Expression: /^Mary/ grep "^Mary" < poem.txt

This matches the word “Mary”, but only when it appears at the beginning of a line.

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>