awk arguments
Thomas Omerzu
omerzu at quando.quantum.de
Tue Jul 24 05:46:10 AEST 1990
In article <290 at sun13.scri.fsu.edu>
mayne at VSSERV.SCRI.FSU.EDU (William (Bill) Mayne) writes:
| Does
| awk '{print $0; print $Y}' Y=X
| print lines from standard input separated by a line containing "X"
| or does it print lines from the file Y=X separated by blank lines,
| since without the assignment the value Y in awk should be null?
[...]
| In fact it does neither. In this case, whether a
| file named Y=X exists or not, standard input is not read and
| nothing is printed.
Obviously awk thinks that filenames are present
if _anything_ follows after the program;
in that case the standard input is not read.
You can avoid this by using '-' as filename argument.
If you add a '-' to your example, it will still not work.
Actually varibles are referenced in awk programs _without_
a leading '$'.
Thus
awk '{print $0; print Y}' Y=X -
will do the job:
read standard input an print contents of every line followed by
a line containing the value of 'Y'.
| I have never been able to get the command line assignment of
| awk variables to work. I have sometimes resorted to ugly kludges
| like using sed to modify an awk program to hard code argument
| values. Surely I have missed something obvious.
exactly: it was the '$'. :-)
| While I am on the subject of awk: I learned about the language
| from the book "The AWK Programming Language" by Kernighan et. al.
| before I started working on unix. I have been disappointed to
| find that the version actually available on every flavor of unix
| I have seen is much weaker than the full version described by the
| book. Are there better versions out there?
Well, I don't know that book
and thus I don't know what weaknesses you're pointing at.
Maybe you could tell us something more specific?
I've always been quite satisfied with the
abilities of 'awk'
- except of one point: the error checking of program scripts.
You'll nearly ever get 'bailing out near line ...'.
That point would have been worth of being mentioned in the
'bug' section of the manual for awk.
--
*-----------------------------------------------------------------------------*
Thomas Omerzu UUCP: ...!unido!quando!omerzu / omerzu at quando.uucp
Quantum GmbH, Bitnet: UNIDO!quando!omerzu / omerzu%quando at UNIDO(.bitnet)
Dortmund, Germany Internet: omerzu at quando.quantum.de
More information about the Comp.unix.wizards
mailing list