MJB@cup.portal.com (Martin J Brown-Jr) (05/03/89)
I just purchased Polytron's Polyshell and Polyawk. While checking out Polyawk I ran across something that struck me as odd. The following piece of "code" runs fine and works as expected, accepting all lines except those that begin with "Command:", and putting the accepted lines in the file d:foo. You will notice the absence of a input filename, which causes Polyawk to accept the input from the keyboard. code follows, enter exactly the same way at the Polyshell prompt: awk '$0 !~ /Command:*/ { print $0 >"d:foo" }' The above code works as expected, but when I had an input filename to this "code", I get a warning that the program will accept and pass on to d:foo all of the input lines (paraphrasing). At which point, the cursor drops to a newline and just blinks, doing nothing until I do a control-c, which dumps me back to the prompt. here is the modified code that just hangs there: awk '$0 !~ /Command:*/ { print $0 >"d:foo" } "d:file.txt"' (note *** quotes were needed around filenames to avoid warnings, I don't think this was documented is this no think this was documented. Is this normal for awk?) Could someone out there explain my error(s)? Would awk react the same way that PolyAWK is reacting? Any further suggestings/ideas? Thanx for any help! - MJB -
jik@athena.mit.edu (Jonathan I. Kamens) (05/04/89)
In article <17886@cup.portal.com> MJB@cup.portal.com (Martin J Brown-Jr) writes: >[He asks why this works: > > awk '$0 !~ /Command:*/ { print $0 >"d:foo" }' > >while this doesn't: > > awk '$0 !~ /Command:*/ { print $0 >"d:foo" } "d:file.txt"' >] What you really mean to do is this: awk '$0 !~ /Command:*/ { print $0 >"d:foo" }' d:file.txt Since you included the filename inside the single quotes, awk thought it was part of the awk command sequence. This way, it will be passed to awk as a separate argument as it should. Jonathan Kamens USnail: MIT Project Athena 410 Memorial Drive, No. 223F jik@Athena.MIT.EDU Cambridge, MA 02139-4318 Office: 617-253-4261 Home: 617-225-8218
MJB@cup.portal.com (Martin J Brown-Jr) (05/05/89)
As Jonathan Kamens pointed out, I needed to move the single quote inside of the file to be read in the following line of INCORRECT "code": awk '$0 !~ /Command:*/ { print $0 >"d:foo" } "d:sourcefile"' ( the ' ( the ' should be after >"d:foo" }' ( the ' should be after >"d:foo" }' in the above code. Thanx to all who helped me with this. No more net bandwidth need be expended on this problem. Problem solved. - MJB -
allbery@ncoast.ORG (Brandon S. Allbery) (05/10/89)
As quoted from <17886@cup.portal.com> by MJB@cup.portal.com (Martin J Brown-Jr):
+---------------
| awk '$0 !~ /Command:*/ { print $0 >"d:foo" } "d:file.txt"'
+---------------
Was this the *exact* quoting?
By putting the file name inside the single quotes, you made it part of the
awk program, *not* an input filename. The result is that it's reading from
the keyboard so it can copy lines not containing "Command" (if this isn't
what you wanted, check that regexp!) to "d:foo", and also attempting to
apply the string "d:file.txt" as a condition. That last might be handled
either as a test for string equality against $0, or as an always "true"
depending on how they did it.
++Brandon
--
Brandon S. Allbery, moderator of comp.sources.misc allbery@ncoast.org
uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu
Send comp.sources.misc submissions to comp-sources-misc@<backbone>
NCoast Public Access UN*X - (216) 781-6201, 300/1200/2400 baud, login: makeuser