Path: utzoo!utgpu!attcan!uunet!pyrdc!pyrnj!rutgers!bellcore!u1100a!krohn
From: krohn@u1100a.UUCP (Eric Krohn)
Newsgroups: comp.lang.c++
Subject: Re: "cut" needed to run CC
Message-ID: <2126@u1100a.UUCP>
Date: 23 Sep 88 15:33:47 GMT
References: <990@acornrc.UUCP> <486@poseidon.UUCP> <911@riddle.UUCP> <809@philmds.UUCP>
Reply-To: krohn@u1100a.UUCP (Eric Krohn)
Organization: Bell Communications Research, Piscataway, NJ
Lines: 42

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