🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1056

Re: Breaking large file into pieces

#1056
From: 4197,ATTT
Date: Wed, 12 Sep 1990 12:46
43 lines
1781 bytes
In article <1990Sep11.134238.20218@dg-rtp.dg.com> monroe@dg-rtp.dg.com (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<number>",
>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?  

Use context split "csplit(1)" to break up the file efficiently. Then
use head/cut/mv to rename the pieces.

csplit -f aaa  /"^xxx-0000"/  {99}  <in-file-name>
rm aaa00
for FN in `ls aaa*`
do
	NFN=`head -1 $FN | cut -d' ' -f1 `
	mv $FN $NFN
done

Bob Rager
Technical Details
Message-ID: <1990Sep12.124634.4872@cbnewsl.att.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!ucsd!pacbell.com!att!cbnewsu!cbnewsl!bonnie!rbr
References: <1990Sep11.134238.20218@dg-rtp.dg.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!ucsd!pacbell.com!att!cbnewsu!cbnewsl!bonnie!rbr
From: rbr@bonnie.ATT.COM (4197,ATTT)
Newsgroups: comp.unix.shell
Subject: Re: Breaking large file into pieces
Message-ID: <1990Sep12.124634.4872@cbnewsl.att.com>
Date: 12 Sep 90 12:46:34 GMT
References: <1990Sep11.134238.20218@dg-rtp.dg.com>
Sender: nntp@cbnewsl.att.com (NetNews Transfer Protocol Login)
Reply-To: rbr@bonnie.ATT.COM (Bob Rager)
Organization: AT&T Bell Laboratories
Lines: 43