Re: Log Analysis and alerting

From: Walter Roberson (roberson@ibd.nrc.ca)
Date: 03/22/02


From: roberson@ibd.nrc.ca (Walter Roberson)
Date: 22 Mar 2002 16:34:16 GMT

In article <3C9B32A3.65A25C2D@attglobal.net>,
Subba Rao <sailorn@attglobal.net> wrote:
[in awk]

:From the command line $_ does print the line

Not in awk or nawk as implimented on SGI IRIX. I do not have my
old AT&T SVS R3 awk manuals handy at the moment, but I'm 99%
certain that $_ is not a part of the awk standard.

On the other hand, if you happen to be using ksh as your shell,
and you happen to be using double-quotes around your script instead
of single, then $_ will be expanded by ksh to mean "the last
argument of the previous command line". If there was no argument
to the previous command line, then it would come out empty, thus
transforming a {print $_} statement into {print } -- and
in awk/nawk, the print command without an argument prints the input.

$ tail /var/adm/SYSLOG | awk "{print $_}"

is $_ treated as a variable in the shell, with that value substituted
in and used just as if it had been typed in to the script.

$ tail /var/adm/SYSLOG | awk '{print $_}'

is $_ treated as a variable by awk, which will complain!

$ tail /var/adm/SYSLOG | nawk '{print $_}'
Illegal field $()
Input record number 1
Source line number 1



Relevant Pages

  • Re: Script to extract portions of text from a text file
    ... > But your example is not comparing the same command. ... it wouldn't be sent to the shell until you press enter). ... >> behaves differently in a script and at the prompt ... While awk does: ...
    (comp.unix.shell)
  • Re: Several Pipes inside an awk script
    ... This series of awk commands work great on the command line: ... You're confused about the difference between an awk script and a shell script. ...
    (comp.lang.awk)
  • Re: Removing lines from a plain text file
    ... Apparently there is no simple command. ... > and put prune in a cron job. ... > size by removing the excess from the beginning of the file. ... date from the past and use awk to search through the file for it and discard ...
    (comp.unix.sco.misc)
  • SUMMARY: awk - command line works / script doesnt
    ... When you enter a command line ... and awk gets exactly the same string handed to it in argv. ... Within a shell script, you need to be careful not to use single ... Packing database blah blah blah ...
    (SunManagers)
  • System() function in awk
    ... I have a custom made script called myscript.ksh and is placed in /tmp. ... Now I want to run the above command through system function in awk ...
    (comp.unix.shell)