Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Jan 2000 18:29:44 +0200
From:      Giorgos Keramidas <charon@hades.hell.gr>
To:        SIVARAM N <sivaramn@wipsys.ge.com>
Cc:        freebsd-newbies@FreeBSD.ORG
Subject:   Re: awk/gawk question
Message-ID:  <20000111182944.B64680@hades.hell.gr>
In-Reply-To: <006a01bf5c11$6bdb5940$8b2fa8c0@wipsys.ge.com>
References:  <006a01bf5c11$6bdb5940$8b2fa8c0@wipsys.ge.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jan 11, 2000 at 02:24:07PM +0530, SIVARAM N wrote:
> Hi,
> 
> If I have a record(s) with the word  "DESC" anywhere within it,
> How do i extract  all chars upto the word "DESC" and  all the chars after
> "DESC" till the end of the line/record separately.
> 
> like for e.g
> DESC : audit file
> ADEIN DESC : file from ADE

If you want to use DESC as the separator of records, you can always
change FS in awk to achieve it.

    $ cat desc.awk
    BEGIN {
      FS = "DESC";
    }
    {
      print NF,":",$1,"/",$2;
    }
    $ cat <<EOF | awk -f desc.awk
    broken DESC fields
    EOF
    2 : broken  /  fields

Watch how spaces are duplicated around "/" in the output, because the
string " DESC " that separates the words 'broken' and 'fields' contains
two extra spaces around "DESC", the value of FS.

-- 
Giorgos Keramidas, < keramida @ ceid . upatras . gr >
"What we have to learn to do, we learn by doing." [Aristotle]


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




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