[net.sources] slice

garyp@cognos.UUCP (Gary Puckering) (12/17/86)

Most humble apologies.  I forgot to include the man page with the
posting for slice.  Here it is.

In addition, the Makefile I posted will copy the man page to section 1,
rather than section l (local), so I've included a revised Makefile.

----------------------- cut here ------------------------------------
#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	slice.1
#	Makefile
# This archive created: Tue Dec 16 20:21:38 1986
export PATH; PATH=/bin:$PATH
echo shar: extracting "'slice.1'" '(5375 characters)'
if test -f 'slice.1'
then
	echo shar: over-writing existing file "'slice.1'"
fi
sed 's/^X//' << \SHAR_EOF > 'slice.1'
X.TH SLICE 1L "1986 December 11" "Cognos Inc."
X.SH NAME
Xslice \- split a file into pieces, by pattern
X.SH SYNOPSIS
X.B slice
X[ \fB\-f \fIfilename\fP ]
X[ \fB\-i\fP\fIn\fP ]
X[ \fB\-a\fP ]
X[ \fB\-x\fP ]
X[ \fB\-m\fP | \fB\-s\fP | \fB\-n\fP\fIn\fP ]
X[ \fIformat\fP .\|.\|. ]
X.LP
X.sp
X.B slice
X[ \fB\-f \fIfilename\fP ]
X[ \fB\-i\fP\fIn\fP ]
X[ \fB\-a\fP ]
X[ \fB\-x\fP ]
X\fB\-e \fIexpression\fP 
X[ \fIformat\fP .\|.\|. ]
X.LP
X.sp
X.B slice
X[ \fB\-f \fIfilename\fP ]
X[ \fB\-i\fP\fIn\fP ]
X[ \fB\-a\fP ]
X[ \fB\-x\fP ]
X\fIexpression\fP
X[ \fIformat\fP .\|.\|. ]
X.SH DESCRIPTION
X.I Slice
Xsplits large files into smaller ones.  The output files are named
Xaccording to the \fIformat\fR strings provided.  The input file is split
Xwhenever a pattern is matched or every \fIn\fR lines, depending on the
Xoptions selected.  The syntax is similar to \fIgrep\fR, except for the
X\fB-f\fR option, which has a different meaning.
XBecause some of the options are mutually exclusive,
Xthere are three forms of the command.
X.LP
XThe options allowed for \fIslice\fR are:
X.IP "\fB-f\fR \fIfilename\fR"
XInput for \fIslice\fR is taken from the named file rather than \fIstdin\fR.
X.IP \-\fBi\fP\fIn\fP
XThe starting number for numbering output files generated by formats
Xcontaining %d (see \fIformat\fR below).  The default starting number is
Xone.
X.IP \fB-a\fR
XCauses the file to be split after the line matching the pattern, rather
Xthan before (as is normally the case).
X.IP \fB-x\fR
XCauses the matched line to be excluded from the output files.  Handy
Xform eliminating cut lines, etc.
X.IP \fB-m\fR
XUses the pattern '^From ' to split the file.  This is convenient for breaking
Xup a mailbox file.
X.IP \fB-s\fR
XUses the pattern '^#!\ */bin/sh' to split the file.  This is ideal for
Xbreaking up mail or news article containing a Bourne shell script.
X.IP \-\fBn\fIn\fR
XSplit the file every \fIn\fR lines.  In this case, no pattern matching 
Xis performed.  This is the behaviour of \fIsplit (1)\fR,
Xexcept that the default output filename format for
X\fIslice\fR is different.
X.IP "\fB-e\fR \fIexpression\fR"
XUses the pattern specified by \fIexpression\fR to split the file.
XThe matched line is put in the new output
Xfile.  The pattern may contain newlines (which match themselves).  See
X.I ed (1)
Xfor details of the regular expressions.
X.IP \fIformat\fR
XAll three forms of the command allow the specification of zero or more
X\fIformat\fR strings as non-flag parameters.
XThe format strings are formed after the fashion of
X.I printf 
Xformats and are used to generate output filenames.
XYou can provide as many as you like.  Every time a split is required,
Xthe next format will be selected.  If \fIslice\fR runs out of
Xformats, a warning will be issued and the last file will contain the
Xremainder of the input file.
X.IP
XA %s in the string will be replaced by the input filename (less pathname).
XIf the input file is \fIstdin\fR, the name \fIslice:\fR will be used
Xas a default.
X.IP
XA %d in a format string will be used to generate a unique number.  
XOnce \fIslice\fR encounters a format containing %d, it will continue
Xusing it until the input file is exhausted.
X.IP
XThe %d is replaced with a number starting at one for the first file, and 
Xincremented by one for each split.  The \-\fBi\fP option can be used
Xto start at a different number.
XThe default format is
X.sp
X\ \ \ \ %s:%03d
X.sp
Xwhich results in files having names like \fIfilename\fR:01, 
X\fIfilename\fR:02, \fIfilename\fR:03 and so on.  
XThe default format was chosen because the resulting files are listed 
Xin numerical order by
X.I ls
Xor by
X.I echo *
Xwhich is sometimes useful.
X.LP
XThe special format string '+' is used to designate that \fIstdout\fR is
Xto be used.  This is handy for piping one of the pieces to another
Xcommand.  Since \fIslice\fR appends to its output files, its possible
Xfor the same filename to appear more than once as a format.
X.LP
X.SH EXAMPLES
XSplit up a mail folder into files slice:001, slice:002, etc.:
X.sp
X	slice -m <folder
X.sp
XSplit a news article containing a shell script into article.hdr and
Xarticle.sh:
X.sp
X	slice -s -f article '%s.hdr' '%s.sh'
X.sp
XSplit stdin at every line of dashes into the files 0, 1, 2, etc.:
X.sp
X	cat anyfile | slice -i0 '^--* *$' '%d'
X.sp
XSplit a news article containing a shell script into its header portion
Xand script portion.  Pipe the latter to \fIsh\fR to unshar it:
X.sp
X	slice -s <article README + | sh
X.sp
XPipe the middle portion of a file to sh, keeping the head and tail in a
Xfile called README (exclude cut lines):
X.sp
X	slice -f myfile -x '^--* [Cc]ut ' README + README | sh
X.sp
XKeep the middle portion of a file, discarding the head and tail:
X.sp
X	slice -f myfile '^--* [Cc]ut ' /dev/null middle /dev/null
X.sp
X.SH BUGS
XWatch out for filename expansion by the shell.  This could cause
X\fIslice\fR to interpret the extra filenames as output formats causing
Xslices to be appended to existing files.
X.SH DIAGNOSTICS
XMostly straight-forward.
X``Internal Error'' indicates a bug in \fIslice\fR, and should be reported.
XExit staus 1 indicates an error parsing options \- for example, if an unknown
Xflag was ued.
XExit status 2 indicates a meaningless combination was detected and rejected
X(this is rare in practice).
XExit status 3 indicates a run-time problem \- for example, if a file couldn't
Xbe opened.
X.SH "SEE ALSO"
X.I ed (1),
X.I mail (1),
X.I ls (1),
X.I split (1),
X.I mailsplit (l),
X.I printf (3).
SHAR_EOF
if test 5375 -ne "`wc -c 'slice.1'`"
then
	echo shar: error transmitting "'slice.1'" '(should have been 5375 characters)'
fi
echo shar: extracting "'Makefile'" '(1233 characters)'
if test -f 'Makefile'
then
	echo shar: over-writing existing file "'Makefile'"
fi
sed 's/^X//' << \SHAR_EOF > 'Makefile'
X# Makefile for slice
X#
X# Originally contributed at mailsplit, written by:
X#   R E Quin, October 1986 University of Warwick (UK) Computer Science
X#   warwick!req     +44 203 523193
X#
X# Modified and recontributed by:
X#   Gary Puckering        3755 Riverside Dr.
X#   Cognos Incorporated   Ottawa, Ontario
X#   (613) 738-1440        CANADA  K1G 3N3
X#
X# This makefile is intended for the sys5 Augmented make.
X# 
XMAKE=make 
XCLEAN=clean 
XCC=cc 
XHACKS= 
XCFLAGS=-O $(HACKS)
X# R is the root of the filesystem -- i.e. where to install things.
X# The binaries are installed in $R/$(DESTDIR).
XR=/usr/local
XDESTDIR=$R/usr/bin 
XMANDIR=$R/usr/man/manl
XPROG=slice 
X
X# PROG is what to make; DESTDIR is where to put it.
X# HACKS are for -DBUGFIX style things.
X
X# R is intended to be the root of the filesystem if it isn't "/"
X
X# "make install " does a $(MAKE) $(CLEAN) at the end, so you can say
X# CLEAN=  make -e install
X# if you don't want to remove the garbage at the end, for example.
X# This is useful primarily for testing the install: entry!
X
Xall: $(PROG)
X 
Xslice: opts.h slice.o
X	$(CC) -o $(PROG) slice.o
X 
Xinstall: slice
X	/bin/mv $(PROG) $(DESTDIR)
X	/bin/cp $(PROG).1 $(MANDIR)/$(PROG).l
X	$(MAKE) $(CLEAN)
X 
Xclean: 
X	rm -rf core *.o $(PROG) a.out
SHAR_EOF
if test 1233 -ne "`wc -c 'Makefile'`"
then
	echo shar: error transmitting "'Makefile'" '(should have been 1233 characters)'
fi
#	End of shell archive
exit 0
-- 
Gary Puckering        3755 Riverside Dr.
Cognos Incorporated   Ottawa, Ontario
(613) 738-1440        CANADA  K1G 3N3