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
krohn@u1100a.UUCP (Eric Krohn) (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: ] [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. Boy, are we getting off on a tangent here! The original problem was that someone was porting C++ to a system that did not supply the cut program, and the CC shell script (as supplied by AT&T) needs cut. Solution: Fix the CC shell script. Here's (very) roughly the scenario: case "$A" in -o*) OO=`echo $A | cut -d"o" -f2-`;; *) # Lots more .... esac Note that cut is used to extract the stuff after the -o (in an amusingly obscure manner). There are lots of simple ways to rewrite that: 1) OO=`echo $A | sed -e 's/^-o//'` 2) OO=`expr $A : '-o\(.*\)'` 3) OO=`echo $A | tail +3c` 4) OO=`echo $A | cut -c3-` I prefer 2) since there is no pipeline and expr is widely available. OK, we didn't have expr in V6, but we didn't have awk then either.... N.B. Trying the echo $A on a Sun running ksh, I got the error: ksh: print: bad option(s) because echo (aliased to the ksh print builtin) tried to interpret the -o! -- -- Eric J. Krohn krohn@ctt.ctt.bellcore.com or {bcr,bellcore}!u1100a!krohn Bell Communications Research, 444 Hoes Ln, Piscataway, NJ 08854
leo@philmds.UUCP (Leo de Wit) (09/24/88)
In article <25047@bu-cs.BU.EDU> tower@bu-it.bu.edu (Leonard H. Tower Jr.) writes: |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. While read is a builtin for the Bourne shell, echo isn't (at least not on Ultrix). The opposite goes for the csh (although it has a notion of $< or something, but I'm too unfamiliar with csh to know whether this can be used to read separate words in a line, like read). What shell are you referring to? The syntax is Bournish. Even if your shell has both builtin, I doubt it can beat sed. Firing up sed took about 0.5 sec, which is less than 5% of the time it took to process the lot. Then it can run along real fast, since sed is designed for text processing, the shell not. Maybe you can come up with some facts and figures - I did too. Leo.