[PLUG] gawking a file

Rich Shepard rshepard at appl-ecosys.com
Thu May 15 07:07:02 UTC 2003


  As all of you are aware, I do not know perl, python or ruby. But, I have
been able to meet my modest needs over the past couple of decades using awk
and sed. Now I'm asking for some sage advice about framing a gawk program to
extract specific fields from a text file.

  Background: I extract certain records from jpilot as a
comma-separated-value (.csv) file. I want only a subset (name, title,
company, address) from the 24 fields there. My one-line gawk program works
just dandy if and only if there is no newline in a jpilot record. When there
is, the extracted file has a record distributed over two or more lines and
that screws up the gawk field extraction.

  There's a valid reason for the newline: some records have a mailing
address that differs from the street address. I use a slash and a newline in
jpilot for readability. I suppose I could use only the slash if I had to.
However, in the notes field, each contact has its own line and there's no
way I can concatenate those and still extract data properly for contact
information.

  So, my question to you more knowledgeble folks is this: Is there a way in
the gawk syntax to specify the field that begins a new record? That is, I
want to match a certain pattern before proceeding to the field extraction.
Would a BEGIN section be the way to go on this?

TIA,

Rich

Dr. Richard B. Shepard, President

                       Applied Ecosystem Services, Inc. (TM)
            2404 SW 22nd Street | Troutdale, OR 97060-1247 | U.S.A.
 + 1 503-667-4517 (voice) | + 1 503-667-8863 (fax) | rshepard@appl-ecosys.com
                         http://www.appl-ecosys.com/





More information about the PLUG mailing list