Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!mintaka!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.shell Subject: Re: ok, i've got a question... Message-ID: <1990Sep27.170227.5257@athena.mit.edu> Date: 27 Sep 90 17:02:27 GMT References: <42900@sequent.UUCP> <9651@jpl-devvax.JPL.NASA.GOV> <42947@sequent.UUCP> Sender: daemon@athena.mit.edu (Mr Background) Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Organization: Massachusetts Institute of Technology Lines: 54 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. 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. Second, as Larry Wall already pointed out, your solution will coredump on a lot of systems. 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. 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. 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): { 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