ok, i've got a question...
Jonathan I. Kamens
jik at athena.mit.edu
Fri Sep 28 03:02:27 AEST 1990
In article <42947 at sequent.UUCP>, lugnut at sequent.UUCP (Don Bolton) writes:
|> awk -f filebelow <oldlist >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 at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8495 Home: 617-782-0710
More information about the Comp.unix.shell
mailing list