home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / shell / 4600 < prev    next >
Encoding:
Internet Message Format  |  1992-11-09  |  1.5 KB

  1. 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
  2. From: loveless@testament.bbn.com (Mary Loveless)
  3. Newsgroups: comp.unix.shell
  4. Subject: Help with shell script
  5. Message-ID: <lft34fINNbid@news.bbn.com>
  6. Date: 9 Nov 92 16:06:39 GMT
  7. Reply-To: loveless@testament.bbn.com. (Mary Loveless)
  8. Distribution: usa
  9. Organization: Bolt Beranek and Newman Inc., Cambridge MA
  10. Lines: 35
  11. NNTP-Posting-Host: bbn.com
  12.  
  13. Hello,
  14.  
  15. I trying to learn shell programing and one of the exercises is to-
  16.  
  17. write my own grep program. Which searches a file for a given pattern,
  18. just as grep does. For each line in the file that matches, print a "window"
  19. around the matching line. That is, print the line preceeding the match, the
  20. matching line, and the line following the match. Be sure to handle the
  21. special cases where the pattern matches the first line of the file, and where
  22. the pattern matches the last line of the file.
  23.  
  24. I'm  trying to use sed - with the following switches - h,x,n . My understanding
  25. of sed is very limited(the book isn't that helpful) But, I'm not  sure  how  to
  26. setup my script. Here is what I have so far -
  27.  
  28.         sed
  29.         "h
  30.          /"$1"/{
  31.                 x
  32.                 print
  33.                 x
  34.                 print
  35.                 n
  36.                 }" < filename
  37.  
  38.  
  39. Am I on the right track?
  40.  
  41. If anyone can help me out I would greatly aprreciate it.
  42.  
  43. Thanks
  44. Mary
  45.  
  46. email - loveless@bbn.com
  47. phone - 617-873-5575
  48.