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