About Us Documentation

Contact Site Map
 

  

WinPak
Documentation

Go to the previous, next chapter.

Output of parts of files

These commands output pieces of the input.

head: Output the first part of files

head prints the first part (10 lines by default) of each file; it reads from standard input if no files are given or when given a file of -. Synopses:

head [option]... [file]...
head -number [option]... [file]...

If more than one file is specicified, head prints a one-line header consisting of

==> file name 
before the output for each file.

head accepts two option formats: the new one, in which numbers are arguments to the options (-q -n 1), and the old one, in which the number precedes any option letters (-1q).

The program accepts the following options. Also see section Common options.

-countoptions -count This option is only recognized if it is specified first. count is a decimal number optionally followed by a size letter (b, k, m) as in -c, or l to mean count by lines, or other option letters (cqv).

-c bytes --bytes=bytes -c --bytes Print the first bytes bytes, instead of initial lines. Appending b multiplies bytes by 512, k by 1024, and m by 1048576.

-n n --lines=n -n --lines Output the first n lines.

-q --quiet --silent -q --quiet --silent Never print file name headers.

-v --verbose -v --verbose Always print file name headers.

tail: Output the last part of files

tail prints the last part (10 lines by default) of each file; it reads from standard input if no files are given or when given a file of -. Synopses:

tail [option]... [file]...
tail -number [option]... [file]...
tail +number [option]... [file]...

If more than one file is specified, tail prints a one-line header consisting of

==> file name 
before the output for each file.

GNU tail can output any amount of data (some other versions of tail cannot). It also has no -r option (print in reverse), since reversing a file is really a different job from printing the end of a file; BSD tail (which is the one with -r) can only reverse files that are at most as large as its buffer, which is typically 32k. A more reliable and versatile way to reverse files is the GNU tac command.

tail accepts two option formats: the new one, in which numbers are arguments to the options (-n 1), and the old one, in which the number precedes any option letters (-1 or +1).

If any option-argument is a number n starting with a +, tail begins printing with the nth item from the start of each file, instead of from the end.

The program accepts the following options. Also see section Common options.

-count +count -count +count This option is only recognized if it is specified first. count is a decimal number optionally followed by a size letter (b, k, m) as in -c, or l to mean count by lines, or other option letters (cfqv).

-c bytes --bytes=bytes -c --bytes Output the last bytes bytes, instead of final lines. Appending b multiplies bytes by 512, k by 1024, and m by 1048576.

-f --follow -f --follow Loop forever trying to read more characters at the end of the file, presumably because the file is growing. Ignored if reading from a pipe. If more than one file is given, tail prints a header whenever it gets output from a different file, to indicate which file that output is from.

-n n --lines=n -n --lines Output the last n lines.

-q -quiet --silent -q --quiet --silent Never print file name headers.

-v --verbose -v --verbose Always print file name headers.

split: Split a file into fixed-size pieces

split creates output files containing consecutive sections of input (standard input if none is given or input is -). Synopsis:

split [option] [input [prefix]]

By default, split puts 1000 lines of input (or whatever is left over for the last section), into each output file.

The output files' names consist of prefix (x by default) followed by a group of letters aa, ab, and so on, such that concatenating the output files in sorted order by file name produces the original input file. (If more than 676 output files are required, split uses zaa, zab, etc.)

The program accepts the following options. Also see section Common options.

-lines -l lines --lines=lines -l --lines Put lines lines of input into each output file.

-b bytes --bytes=bytes -b --bytes Put the first bytes bytes of input into each output file. Appending b multiplies bytes by 512, k by 1024, and m by 1048576.

-C bytes --line-bytes=bytes -C --line-bytes Put into each output file as many complete lines of input as possible without exceeding bytes bytes. For lines longer than bytes bytes, put bytes bytes into each output file until less than bytes bytes of the line are left, then continue normally. bytes has the same format as for the --bytes option.

csplit: Split a file into context-determined pieces

csplit creates zero or more output files containing sections of input (standard input if input is -). Synopsis:

csplit [option]... input pattern...

The contents of the output files are determined by the pattern arguments, as detailed below. An error occurs if a pattern argument refers to a nonexistent line of the input file (e.g., if no remaining line matches a given regular expression). After every pattern has been matched, any remaining input is copied into one last output file.

By default, csplit prints the number of bytes written to each output file after it has been created.

The types of pattern arguments are:

n Create an output file containing the input up to but not including line n (a positive integer). If followed by a repeat count, also create an output file containing the next line lines of the input file once for each repeat.

/regexp/[offset] Create an output file containing the current line up to (but not including) the next line of the input file that contains a match for regexp. The optional offset is a + or - followed by a positive integer. If it is given, the input up to the matching line plus or minus offset is put into the output file, and the line after that begins the next section of input.

%regexp%[offset] Like the previous type, except that it does not create an output file, so that section of the input file is effectively ignored.

{repeat-count} Repeat the previous pattern repeat-count additional times. repeat-count can either be a positive integer or an asterisk, meaning repeat as many times as necessary until the input is exausted.

The output files' names consist of a prefix (xx by default) followed by a suffix. By default, the suffix is an ascending sequence of two-digit decimal numbers from 00 and up to 99. In any case, concatenating the output files in sorted order by filename produces the original input file.

By default, if csplit encounters an error or receives a hangup, interrupt, quit, or terminate signal, it removes any output files that it has created so far before it exits.

The program accepts the following options. Also see section Common options.

-f prefix --prefix=prefix -f --prefix Use prefix as the output file name prefix.

-b suffix --suffix=suffix -b --suffix Use suffix as the output file name suffix. When this option is specified, the suffix string must include exactly one printf(3)-style conversion specification, possibly including format specification flags, a field width, a precision specifications, or all of these kinds of modifiers. The format letter must convert a binary integer argument to readable form; thus, only d, i, u, o, x, and X conversions are allowed. The entire suffix is given (with the current output file number) to sprintf(3) to form the file name suffixes for each of the individual output files in turn. If this option is used, the --digits option is ignored.

-n digits --digits=digits -n --digits Use output file names containing numbers that are digits digits long instead of the default 2.

-k --keep-files -k --keep-files Do not remove output files when errors are encountered.

-z --elide-empty-files -z --elide-empty-files Suppress the generation of zero-length output files. (In cases where the section delimiters of the input file are supposed to mark the first lines of each of the sections, the first output file will generally be a zero-length file unless you use this option.) The output file sequence numbers always run consecutively starting from 0, even when this option is specified.

-s -q --silent --quiet -s -q --silent --quiet Do not print counts of output file sizes.


 

 

Email addresses listed on this site may  NOT be used for unsolicited commercial email.

Ready-to-Run Software, Inc Privacy Statement

Portions (c)Copyright, 1996-2005 by Ready-to-Run Software, Inc
(All rights reserved.)
212 Cedar Cove
Lansing, NY 14882
Phone: 607 533 UNIX (8649)
Fax: 607 533 4002