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

  1. Path: sparky!uunet!ukma!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!news!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: Erasing words with less than n letters
  5. Message-ID: <1992Nov5.183133.1471@netlabs.com>
  6. Date: 5 Nov 92 18:31:33 GMT
  7. References: <1992Nov4.180618.9183@inesc.pt> <1992Nov5.011854.25944@umbc3.umbc.edu>
  8. Sender: news@netlabs.com
  9. Organization: NetLabs, Inc.
  10. Lines: 44
  11. Nntp-Posting-Host: scalpel.netlabs.com
  12.  
  13. In article <1992Nov5.011854.25944@umbc3.umbc.edu> rouben@math9.math.umbc.edu (Rouben Rostamian) writes:
  14. : In article <1992Nov4.180618.9183@inesc.pt> jota@iguana.inesc.pt writes:
  15. : >    Is there a way of erasing the words with less than n letters
  16. : >using unix ? sed ? awk ? The words (in a dictionary) are sorted and
  17. : >one per line.
  18. : To print input lines containing n or more characters:
  19. : awk 'length($0) >= n { print }'
  20.  
  21. Here it is in sed (using 9 for our "n" to avoid confusion with -n):
  22.  
  23.     sed -n '/.\{9\}/p'
  24.  
  25. Of course, maybe you prefer grep:
  26.  
  27.      grep '.\{9\}'
  28.  
  29. Or nroff:
  30.  
  31.     #!/bin/sh
  32.  
  33.     (
  34.     cat <<-'END'
  35.         .de TR
  36.         'di
  37.         .pl 1000v
  38.         .if \\n(dl/24>=9 .aa
  39.         .ST
  40.         ..
  41.         .de ST
  42.         .pl 1n
  43.         'di aa
  44.         .nr .i 0
  45.         .it 1 TR
  46.         ..
  47.         .nf
  48.         .ST
  49.         END
  50.     cat ${1-"$@"}
  51.     ) | nroff
  52.  
  53. Larry Wall
  54. lwall@netlabs.com
  55.