home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pmafire!news.dell.com!swrinde!sdd.hp.com!spool.mu.edu!hri.com!noc.near.net!news.bbn.com!testament.bbn.com!loveless
- From: loveless@testament.bbn.com (Mary Loveless)
- Newsgroups: comp.unix.shell
- Subject: Help with shell script
- Message-ID: <lft34fINNbid@news.bbn.com>
- Date: 9 Nov 92 16:06:39 GMT
- Reply-To: loveless@testament.bbn.com. (Mary Loveless)
- Distribution: usa
- Organization: Bolt Beranek and Newman Inc., Cambridge MA
- Lines: 35
- NNTP-Posting-Host: bbn.com
-
- Hello,
-
- I trying to learn shell programing and one of the exercises is to-
-
- write my own grep program. Which searches a file for a given pattern,
- just as grep does. For each line in the file that matches, print a "window"
- around the matching line. That is, print the line preceeding the match, the
- matching line, and the line following the match. Be sure to handle the
- special cases where the pattern matches the first line of the file, and where
- the pattern matches the last line of the file.
-
- I'm trying to use sed - with the following switches - h,x,n . My understanding
- of sed is very limited(the book isn't that helpful) But, I'm not sure how to
- setup my script. Here is what I have so far -
-
- sed
- "h
- /"$1"/{
- x
- print
- x
- print
- n
- }" < filename
-
-
- Am I on the right track?
-
- If anyone can help me out I would greatly aprreciate it.
-
- Thanks
- Mary
-
- email - loveless@bbn.com
- phone - 617-873-5575
-