Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!decwrl!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.shell Subject: Re: Breaking large file into pieces Message-ID: <1990Sep11.200555.14626@iwarp.intel.com> Date: 11 Sep 90 20:05:55 GMT References: <1990Sep11.134238.20218@dg-rtp.dg.com> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 46 In-Reply-To: monroe@dg-rtp.dg.com (Mark A Monroe) In article <1990Sep11.134238.20218@dg-rtp.dg.com>, monroe@dg-rtp (Mark A Monroe) writes: | I want to rip a large file into pieces, naming new files according | to an ID string in the large file. For example, the large file contains | records that look like this: | | xxx-00001239 data data data | description | . | . | (variable length) | . | <---blank line | xxx-00001489 data data data | description | . | . | (variable length) | . | <---blank line | xxx-00001326 data data data | | When I find a line in the large data file that starts | with "xxx-0000", I want to open a file named "xxx-0000", | like "xxx-00001489", and write every line, including | the current one, into it. When I see another "xxx-0000", | I want to close the file, open a new file named for the new id | string, and continue writing. At the end of the large data | file, close all files and exit. | | Any suggestions? You didn't say "and I don't want it in Perl", so I'm considering this solution fair game... perl -pe 'open(STDOUT,">$1") if /^(xxx-\d+)/;' bigdatafile Pretty durn simple. The right tool for the job. Yeah, you could do it with an awk script feeding into a /bin/sh (or with a smarter awk), but this is too easy. Just another Perl hacker, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/