home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / shell / 3948 < prev    next >
Encoding:
Internet Message Format  |  1992-09-14  |  1.4 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!spool.mu.edu!hri.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!news.mit.edu!jdell
  2. From: jdell@zenobia.mit.edu (John Ellithorpe)
  3. Newsgroups: comp.unix.shell
  4. Subject: Help with awk
  5. Message-ID: <JDELL.92Sep14134304@zenobia.mit.edu>
  6. Date: 14 Sep 92 18:43:04 GMT
  7. Sender: news@athena.mit.edu (News system)
  8. Distribution: comp.unix.shell
  9. Organization: Massachusetts Institute of Technology
  10. Lines: 31
  11. Nntp-Posting-Host: zenobia.mit.edu
  12.  
  13. Hi,
  14.  
  15. I've got a question about awk.  I need to minimum match with a variable in 
  16. a shell script.  What I want to do is something like:
  17.  
  18. #!/bin/sh
  19. tstusr=$1
  20. user=`awk -F: '$1 ~ /^$tstusr/ {print $1}' passwd`
  21. echo $user
  22.  
  23. And in the passwd file is:
  24.  
  25. jdell:...
  26.  
  27. So, when I run the script:
  28.  
  29. % script jde
  30. jdell
  31.  
  32. it should come up with the minimum matched username(s).  But I can't get
  33. awk to recognize /^$tstusr/.  Is there a way to do this?
  34.  
  35. John
  36. --
  37.  
  38. ===============================================================================
  39. John Ellithorpe                           | Internet: jdell@maggie.mit.edu
  40. Dept. of Physics, Rm 26-349               | Phone   : (617) 253-3074  Office
  41. Massachusetts Institute of Technology     |           (617) 253-3072  Lab
  42. Cambridge, MA  02139                      |           (617) 236-4910  Home
  43. ===============================================================================
  44.