home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / ultrix / 5836 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  1.4 KB

  1. Path: sparky!uunet!usc!sdd.hp.com!uakari.primate.wisc.edu!ames!network.ucsd.edu!nic!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.unix.ultrix
  4. Subject: Re: How do you cat together files without getting subdirs?
  5. Message-ID: <1992Jul22.194139.20215@netlabs.com>
  6. Date: 22 Jul 92 19:41:39 GMT
  7. References: <110593@muvms3.bitnet> <1992Jul22.010325.27235@decuac.dec.com>
  8. Sender: news@netlabs.com
  9. Organization: NetLabs, Inc.
  10. Lines: 31
  11. Nntp-Posting-Host: scalpel.netlabs.com
  12.  
  13. In article <1992Jul22.010325.27235@decuac.dec.com> mjr@hussar.dco.dec.com (Marcus J. "will do TCP/IP for food" Ranum) writes:
  14. : To get all files in a directory that are not subdirectories or devices:
  15. :     (for a in *; do
  16. :         if [ -f "$a" ]; then
  17. :             cat $a
  18. :         fi
  19. :     done) > /tmp/output
  20. : There is probably some way to do this with a single grotty line of perl...
  21.  
  22. Grotty perhaps, but it's fairly understandable grot, and only one process.
  23. You can probably figure out what grep() does here without coaching.
  24.  
  25.     perl -e '@ARGV = grep(-f, @ARGV); print while <>' *
  26.  
  27. Closely related (and generally more useful) is
  28.  
  29.     perl -e '@ARGV = grep(-T, @ARGV); print while <>' *
  30.  
  31. which just cats the text files, if, for instance, you wanted to print
  32. all the printable files in your directory.  In Perl version 5 you'll
  33. be able to say
  34.  
  35.     perl -pe 'BEGIN { @ARGV = grep(-T, @ARGV) } print'
  36.  
  37. which awkophiles may be a little more comfy with.
  38.  
  39. Larry Wall
  40. lwall@netlabs.com
  41.