Article View: comp.unix.shell
Article #1052Re: Breaking large file into pieces
From: Tim.Ouellette
Date: Wed, 12 Sep 1990 08:08
Date: Wed, 12 Sep 1990 08:08
51 lines
2262 bytes
2262 bytes
>>>>> On 11 Sep 90 13:42:38 GMT, monroe@dg-rtp.dg.com (Mark A Monroe) said:
Mark> I want to rip a large file into pieces, naming new files according
Mark> to an ID string in the large file. For example, the large file contains
Mark> records that look like this:
Mark> xxx-00001239 data data data
Mark> description
Mark> .
Mark> .
Mark> (variable length)
Mark> .
Mark> <---blank line
Mark> xxx-00001489 data data data
Mark> description
Mark> .
Mark> .
Mark> (variable length)
Mark> .
Mark> <---blank line
Mark> xxx-00001326 data data data
Mark> When I find a line in the large data file that starts
Mark> with "xxx-0000", I want to open a file named "xxx-0000<number>",
Mark> like "xxx-00001489", and write every line, including
Mark> the current one, into it. When I see another "xxx-0000",
Mark> I want to close the file, open a new file named for the new id
Mark> string, and continue writing. At the end of the large data
Mark> file, close all files and exit.
Mark,
Here's an awk solution.
------------------------split.awk-----------------------
BEGIN{pcFile="/dev/null";}
/xxx-[0123456789]+/{close(pcFile);pcFile = $1;}
{print $0 >> pcFile;}
--------------------------------------------------------
execute it by
awk -f split.awk datafile
Hope this helps
--
Timothy R. Ouellette
NCR Microelectronics Tim.Ouellette@FtCollins.ncr.com
Ft. Collins, CO. uunet!ncrlnk!ncr-mpd!bach!timo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"If all the world is a stage, I want to run the trap door" -- P. Beaty
Technical Details
Message-ID:
<TIM.OUELLETTE.90Sep12090810@sousa.FtCollins.NCR.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!emory!hubcap!ncrcae!ncrlnk!ncr-mpd!Tim.OuelletteReferences:
<1990Sep11.134238.20218@dg-rtp.dg.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!emory!hubcap!ncrcae!ncrlnk!ncr-mpd!Tim.Ouellette From: Tim.Ouellette@FtCollins.NCR.COM (Tim.Ouellette) Newsgroups: comp.unix.shell Subject: Re: Breaking large file into pieces Message-ID: <TIM.OUELLETTE.90Sep12090810@sousa.FtCollins.NCR.COM> Date: 12 Sep 90 08:08:10 GMT References: <1990Sep11.134238.20218@dg-rtp.dg.com> Sender: uucp@ncr-mpd.FtCollins Organization: NCR Microelectronics, Ft. Collins, CO Lines: 51 In-reply-to: monroe@dg-rtp.dg.com's message of 11 Sep 90 13:42:38 GMT