Path: utzoo!attcan!uunet!mailrus!wuarchive!mit-eddie!uw-beaver!zephyr.ens.tek.com!tektronix!sequent!lugnut From: lugnut@sequent.UUCP (Don Bolton) Newsgroups: comp.unix.shell Subject: Re: ok, i've got a question... Message-ID: <43113@sequent.UUCP> Date: 27 Sep 90 22:05:49 GMT References: <42900@sequent.UUCP> <9651@jpl-devvax.JPL.NASA.GOV> <42947@sequent.UUCP> <1990Sep27.170227.5257@athena.mit.edu> Reply-To: lugnut@sequent.UUCP (Don Bolton) Organization: Sequent Computer Systems, Inc Lines: 85 In article <1990Sep27.170227.5257@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes: >In article <42947@sequent.UUCP>, lugnut@sequent.UUCP (Don Bolton) writes: >|> awk -f filebelow newlist >|> >|> { for (i = 1; i <= NF; i = i + 1) >|> { if (i >= NF) >|> printf("%s",$i) >|> else >|> printf("%s ", $i) >|> } >|> printf("\n") >|> } >|> >|> course I assume the "null" characters are just blanks here > > First of all, the assumption that the nulls are supposed to represent blanks >in the text is faulty, and is (as far as I can tell) in no way a valid >assumption given the data that was provided by the original poster. >Furthermore, there is no reason to make that assumption, since other posters >have posted solutions which do not. > This is true, alas, I work with RDBMS products such as Oracle and Informix and am used to seeing nulls represented as blank spaces. > Note that the original poster did not say that he wanted to replace the >nulls with spaces (which is what your solution does), he said that he wanted >to remove them altogether. > Actualy what my program does do is strip out multiple blanks and replaces them with one blank space. > Second, as Larry Wall already pointed out, your solution will coredump on a >lot of systems. > This is not a point I would have considered, as it runs fine on my machine and is really merely a modified example from the awk programming language book I have. > Third, your solution deletes extra space between words. If I have a line >which appears as "foo bar" in the input, it will appear as "foo bar" >in the output. > Which was my intent. (I did do *something* right) :-) > Fifth, the awk on my system (4.3BSD) loses anything on the line after the >first null. Therefore, "foo^@^@^@bar" turns into "foo". Presumably, your >version doesn't do this, else you wouldn't have posted your solution, so you >have portability concerns. There are still other versions of awk (e.g. GNU >awk) that keep nulls intact. > Don't know bout this one.... > Sixth, the awk code you posted is suboptimal in at least three different >ways. For example, if you look runs from 1 to NF, how can i ever be greater >than NF inside the body of the loop? Here's a piece of code that does the >same thing (although, like I've said, I don't think it's the right thing to >do): > i cannot be greater than NF, this bozo hosehead here tried to use an assignment operand as an equality operator, in a fit of "what the fu**", I tossed in the > and bingo it ran. 16 months ago I was a telemonkey (read telemarketer) with { > for (i = 1; i < NF; i++) > printf("%s ", $i) > printf("%s\n", $NF) > } > >-- >Jonathan Kamens USnail: >MIT Project Athena 11 Ashford Terrace >jik@Athena.MIT.EDU Allston, MA 02134 >Office: 617-253-8495 Home: 617-782-0710 Half lug, half nut