Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 04 Oct 2001 21:04:51 -0600
From:      Chris Fedde <chris@fedde.littleton.co.us>
To:        "Kory Hamzeh" <kory@avatar.com>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Real dumb shell script/awk question 
Message-ID:  <200110050304.f9534pK39202@fedde.littleton.co.us>
In-Reply-To: <001201c14d37$3a59fac0$14ce21c7@avatar.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 4 Oct 2001 17:46:53 -0700  "Kory Hamzeh" wrote:
 +------------------
 | 
 | I need to bang together a simple shell script to parse a flat ascii
 | database. The fields are variable width, but each field is separated by the
 | "|" character. Basically, all this script needs to do is to read the
 | database, one line at a line, and if field X is equal to value Y, then print
 | the value of field Z. The user must be able to specify X, Y, and Z on the
 | command line.
 | 
 | Now, for the life of me, I can't seem to figure out a simple way of doing
 | this with a bourne shell script. I think awk can do it, but the man pages
 | didn't help me too much with the language. I know other language, like perl,
 | are probably better suited, but I need to customize this script per the
 | clients request, and it will only be needed for a couple of weeks and he'll
 | never need this again.
 | 
 | Any tips on how to do this? I'm sure there is a simple way and I'm drawing a
 | blank.
 +------------------

Awk is your friend

    $ cat t
    asdf|trew|agfd
    asdf|asdf|435
    wer|asgf|bwhw
    qwert|qewrt|asdf

    $ awk -F'|' -e '$1 == $2 {print $3}' t
    435

Good luck!

--
    Chris Fedde

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200110050304.f9534pK39202>