[comp.unix.questions] "cut" needed to run CC

mhyman@cup.portal.com (08/19/88)

Bob Weissman (bob@acornrc.uucp) asks:
 >The CC script which runs the AT&T C++ compiler makes reference
 >to a program called "cut", which does not exist on BSD systems.
 >
 >What is "cut"?

From the SunOS 3.2 man page

	cut - remove selected fields from each line of a file

--Marc  (...!sun!portal!cup.portal.com!mhyman)

ech@poseidon.UUCP (Edward C Horvath) (09/02/88)

In article <990@acornrc.UUCP> bob@acornrc.UUCP (Bob Weissman) writes:
>The CC script which runs the AT&T C++ compiler makes reference
>to a program called "cut", which does not exist on BSD systems.

'cut' selects character-columns (-c) or tab-separated fields (-f) from the
named files or stdin, and copies the result to stdout.  e.g.
echo "How are you today" | cut -d" " -f1,3
will yield "How you". (the -d overrides the separator character).

It isn't (quite) a database projection, in that cut -f3,1 is the same as
cut -f1,3.  Some Unices may have my ncut(1) command that does -f3,1 properly.

More details: see any AT&T Unix User's Manual.

=Ned Horvath=

domo@riddle.UUCP (Dominic Dunlop) (09/16/88)

In article <486@poseidon.UUCP> ech@poseidon.UUCP (XT1554000-Edward C Horvath;LZ 3F-315;3005) writes:
>In article <990@acornrc.UUCP> bob@acornrc.UUCP (Bob Weissman) writes:
>>The CC script which runs the AT&T C++ compiler makes reference
>>to a program called "cut", which does not exist on BSD systems.
>
>'cut' selects character-columns (-c) or tab-separated fields (-f) from the
>named files or stdin, and copies the result to stdout.  e.g.
>echo "How are you today" | cut -d" " -f1,3
>will yield "How you". (the -d overrides the separator character).
>
>More details: see any AT&T Unix User's Manual.

Quick hack fix: echo "How are you today" | awk -d" " '{print $1 " " $3}'

More details: see any UNIX User's manual from any source whatever.

With a little shell hacking, you could probably write a shell script called
cut that made awk look enough like cut to fool the BSD compiler.
Volunteers?

And yes, awk can correctly do database projection if that's what you need.
(I speak as one who squeezes reports out of relational databases by using
SQL followed by awk followed by troff.  In exceptional cases, I've had awk
write a shell script which, on being interpreted, drives troff...)  (But
you don't want to hear about my embarrassing databation habit, do you?)

It's my experience that all UN*X systems now provide awk at no extra cost --
although you may have to install a few modules above and beyond the
minimal ``runtime system'' (or whatever the supplier calls it) in order to
get it onto the system.  (In the bad old days, you had to pay extra in
order to get it on some machines -- boo, hiss.)

It is left as an exercise for the reader to perform the operation above
using sed.  Clue: it ain't pretty...
-- 
Dominic Dunlop
domo@sphinx.co.uk  domo@riddle.uucp

leo@philmds.UUCP (Leo de Wit) (09/18/88)

In article <911@riddle.UUCP> domo@riddle.UUCP (Dominic Dunlop) writes:
    [lines deleted]...
>Quick hack fix: echo "How are you today" | awk -d" " '{print $1 " " $3}'
    [more lines deleted]...
>It is left as an exercise for the reader to perform the operation above
>using sed.  Clue: it ain't pretty...

Not so pretty as awk, but not as ugly as some nroff scripts I've seen 8-).
Testing an sed-version however revealed it was almost 4 times as fast as
the awk version.
Consider:

------------ start here for awk version --------------
#!/bin/sh
# cut by awk

exec awk -d" " '{print $1 " " $3}' $*
------------ end   here --------------

and

------------ start here for sed version --------------
#!/bin/sh
# cut by sed

sp='  *'
wd='[^ ][^ ]*'

exec sed "s/$sp$wd$sp\\($wd\\).*/ \\1/" $*
------------ end   here --------------

On a source text (a News mailbox) of about 180Kbyte this was the result:

awk-version
       44.1 real        41.4 user         1.8 sys
sed-version
       12.3 real        10.5 user         1.1 sys

Output was redirected to /dev/null; directing it to a file will probably
increase both real and sys time slightly.
If you are going to use it with a compiler, you'd better make sure it's
fast, considering how often and for how large inputs it is going to be
used.  Maybe it's even worth considering writing a small C program for
it, although I doubt this will gain much over the sed version.

           Leo.

B.T.W. Although awk has builtin mechanisms for handling words ($1 etc),
it is pretty disappointing here. Anyone cares to check out perl on this one?

tower@bu-cs.BU.EDU (Leonard H. Tower Jr.) (09/23/88)

In article <809@philmds.UUCP> leo@philmds.UUCP (Leo de Wit) writes:
|In article <911@riddle.UUCP> domo@riddle.UUCP (Dominic Dunlop) writes:
| ... <awk and sed scripts deleted> ...

This shell script does the job:

while read c1 c2 c3 c4
do
	echo $c1 $c3
done

As it only uses built-ins, it will scream along fine.  

enjoy -len