home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / shell / 3498 < prev    next >
Encoding:
Text File  |  1992-08-16  |  1.2 KB  |  36 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!clsi!mitch
  3. From: mitch@clsi (Mitchell N. Perilstein)
  4. Subject: Re: searching for 1st occurrence
  5. In-Reply-To: bduncan@ve3ied.UUCP's message of Fri, 14 Aug 1992 01:21:56 GMT
  6. Message-ID: <MITCH.92Aug16153742@mira.clsi>
  7. Sender: usenet@clsi.COM
  8. Organization: CAD Language Systems, Inc.
  9. References: <15m8aqINN6ci@seven-up.East.Sun.COM> <1992Aug14.012156.5499@ve3ied.UUCP>
  10. Date: 16 Aug 92 15:37:42
  11. Lines: 23
  12.  
  13. > In article <15m8aqINN6ci@seven-up.East.Sun.COM> ltaylor@blinky.East.Sun.COM (Laura Taylor) writes:
  14. >Inside a shellscript, I would like to search for only the
  15. >first occurrence of a particular string, or in otherwords,
  16. >just one occurrence of the same string so I can set it to
  17. >a variable.
  18. >
  19. >For example, say in file called systems, there is a list of
  20. >all the system architectures something like...
  21. >
  22. >SS2
  23. >SS1
  24. >SS2
  25. >4/75
  26.  
  27. You can just skip the grep and do it in one step:
  28.  
  29.     awk '/SS2/ {print; exit}' < systems
  30.  
  31. You might want a better regexp, like /^SS2$/.
  32. ---
  33.  Mitchell N. Perilstein                          5457 Twin Knolls Rd
  34.  CAD Language Systems, Inc.                      Suite 101
  35.  410-992-5700                                    Columbia, MD 21045-3259
  36.