Re: Collect errors from a file

From: Juhan Leemet (juhan_at_logicognosis.com)
Date: 11/09/04


Date: Tue, 09 Nov 2004 19:17:17 -0300

On Mon, 08 Nov 2004 11:10:16 -0500, Dale DeRemer wrote:

> I run a job that dumps errors from our application into to a comma separated
> file.
> I want to read the 5th field of this file and write the entire line to
> another file if it contains a specified value.
> I know awk -F[,] '{print $5}' file.csv > result.txt
> Will send the 5th field to another file. What I really need is to find and
> send the entire line to another file if $5 = 1.
> Any ideas?

You need a pattern to be matched in there, like:

        awk -F, '$5==1 {print}' file.csv >result.txt

The Solaris man page for awk has some words about

        pattern { action }

The Linux man page has similar words.

BTW, there is a comp.lang.awk newsgroup specifically for awk stuff.

p.s. First go around, I made the typical newbie typo $5=1 which ended up
printing all lines with 5th field as 1. Don't make that mistake.

-- 
Juhan Leemet
Logicognosis, Inc.


Relevant Pages

  • Re: Help Please - awk works directly but not in a script
    ... There is a regular expression error. ... I have removed the "$" sign before T, Now its printing the entire file ... I have no awk at hand to check, ... This is printing what I wanted, when I directly substitute the value ...
    (comp.lang.awk)
  • Re: printing odd columns
    ... > I cannot figure out a way of printing only the odd numbered columns in ... awk ' { ...
    (comp.lang.awk)
  • Re: How to record a time, when specific message appears in console?
    ... "Juhan Leemet" wrote in message ... >> I have a program which produces console output. ... > Sounds to me like you are duplicating some syslog functionality. ... This is th trick execute command, printed out by awk. ...
    (comp.unix.shell)
  • Re: help returning a value on a line...
    ... It seems like it would be an easy task with ... > something like awk or sed and I have searched for an answer. ... > the value with sed and I have a way of printing the value with awk but it ... > is cumbersome because the value is not in the same place for each line. ...
    (comp.unix.shell)
  • Re: sed scripting
    ... and replace the rest of the occurrences. ... For anything other than simple substitutions, use awk or perl or ruby or... ... I don't suppose you know how to suppress the printing to screen? ...
    (comp.unix.shell)