Dec 072017
C source to Unix like cut & paste programs.
File CUTPASTE.ZIP from The Programmer’s Corner in
Category C Source Code
C source to Unix like cut & paste programs.
File Name File Size Zip Size Zip Type
CUT.C 10112 3654 deflated
CUT.DOC 5632 2079 deflated
PASTE.C 11904 4325 deflated
PASTE.DOC 7552 2364 deflated

Download File CUTPASTE.ZIP Here

Contents of the CUT.DOC file

Page 1 (last mod. 8/19/84)


cut -cut outselected fieldsof eachline ofa file

ccccuuuutttt ----cccclist [file1 file2 ...]
ccccuuuutttt ----fffflist [----dddd char] [----ssss] [file1 file2 ...]

Use _c_u_t to cut out columns from a table or fields from each
line of a file; in data base parlance, it implements the
projection ofa relation. The fieldsas specified by_l_i_s_t
can be fixed length, i.e., character positions as on a
punched card (----cccc option), or the length can vary fromline
to line and be markedwith a field delimiter character like
_t_a_b (----ffff option). _C_u_tcan be used as a filter; if no files
are given, the standard inputis used.

The meanings of the options are:

A comma-separated list of integer field numbers (in
increasing order), with optional - to indicate ranges as in
the ----oooo option of _n_r_o_f_f/_t_r_o_f_ffor page ranges; e.g., 1111,,,,4444,,,,5555;
1111----3333,,,,8888; ----5555,,,,11110000(short for 1111----5555,,,,11110000PPPP))));;;; oooorrrr3333---- ((((sssshhhhoooorrrrtttt ffffoooorrrr tttthhhhiiiirrrrdddd
tttthhhhrrrroooouuuugggghhhh llllaaaassssttttffffiiiieeeelllldddd))))....

The _l_i_s_t following ----cccc (no space) specifies character
positions (e.g., ----cccc1111----77772222 would pass the first72 characters
of each line).

The _l_i_s_t following ----ffff is a list of fields assumed tobe
separated inthe file by a delimitercharacter (see ----dddd);
e.g., ----ffff1111,,,,7777 copies the firstand seventh field only. Lines
withno field delimiters will be passed through intact
(useful for table subheadings), unless ----ssss isspecified.

The character following ----dddd is the field delimiter (----ffff
option only). Default is _t_a_b. Space or other characters
withspecialmeaningto the shell must be quoted.

Supresses lines withno delimiter charactersin caseof ----ffff
option. Unless specified, lines with no delimiters will be
passed through untouched.

Either the ----ccccor ----ffff option must be specified.

Use _g_r_e_p(1) to make horizontal "cuts"(by context) through a

Page 1 (last mod. 8/19/84)


file or _p_a_s_t_e(1) to put filestogether column-wise (i.e.,
horizontally). To reorder columns ina table, use _c_u_t and

cut -d: -f1,5/etc/passwd
mapping of user IDsto names

name=`who am icut -f1-d
to set nnnnaaaammmmeeeeto current login name

_l_i_n_e _t_o_o _l_o_n_g
A line can have no more than 511 charactersor fields.

_b_a_d _l_i_s_t _f_o_r _c/_f _o_p_t_i_o_n
Missing ----cccc or ----ffff option or incorrectly specified _l_i_s_t. No
error occurs if a line has fewer fields than the _l_i_s_t
calls for.

_n_o _f_i_e_l_d_s
The_l_i_s_t isempty.


This program is a complete rewrite ofthe Bell Laboratories
command of the same name; no part of the original source or
manual is included. Therefore, you may feel free to use it,
and its source, without violation of any contract
agreements. However,I retain the copyright in orderto
specify it remain available for use by all and sundry,
without cost. Feel free to modify asnecessary, although I
went to greatpains to recreate the behavior of the original
command; I would suggest thiscongruence be maintained.

Alongthe same lines,although I've made a reasonableeffort
to test the more arcane behavior of the original _c_u_t and
reproduce it,there are no guarantees. I remain in no way
liable for any loss, either explicit or incidental, that may
be incurred through use of this command. I do ask that any
bugs (and, hopefully,fixes) be reported backto me as
encountered. - David M. Ihnat, ihuxx!ignatz

Page 2 (last mod. 8/19/84)

 December 7, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>