Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create delimitted flat file with /var/mail/filename

Status
Not open for further replies.

EG22

IS-IT--Management
Nov 13, 2001
3
US
I am new w/AWK and need assistance on creating a flat comma delimitted file from a /var/mail/filename

Here is the file format:

Submitted Date: 06/22/99
Submitted Time: 11:26:58

Confirmation Identification Number: 33334444

User Information:

First Name.............: ED
Last Name..............: Je
Address................: 14 Autumn Tr.
City...................: San Antonio
State..................: TX
ZIP....................: 77062
Country................: usa
Phone..................: 281 222 4444
Email..................: ed@hotmail.com

Additional Information:
This is the text being submitted by the person filling out the form. It can grow from one sentence to many.


Submitted Date: 06/22/01
Submitted Time: 12:26:58

Confirmation Identification Number: 33335555

User Information:

First Name.............: Joe
Last Name..............: Lewis
Address................: 14 Autumn Tr.
City...................: San Antonio
State..................: TX
ZIP....................: 77062
Country................: usa
Phone..................: 281 222 4444
Email..................: ed@hotmail.com

Additional Information:
This is the text being submitted by the person filling out the form. It can grow from one sentence to many.

##################

OUTPUT DESIRED:

06/22/99,11:26:58,33334444,ED,Je,14 Autumn Tr.,San Antonio,TX,77062,USA,281 222 4444,ed@hotmail.com,This is the text being submitted by the person filling out the form. It can grow from one sentence to many.

06/22/01,12:26:58,33335555,Joe,Lewis,14 Autumn Tr.,San Antonio,TX,77062,USA,281 222 4444,ed@hotmail.com,This is the text being submitted by the person filling out the form. It can grow from one sentence to many.


Thanks in advance.

EG22
 
Hi EG22,

This awk program should do what you want.
Code:
{
  if (flg) {
    print
    flg = 0
    next
  }
  if ($0 ~ "^Additional Information") {
    flg = 1
    next
  }
  j = index($0,":")
  if (j) printf substr($0,j+1)
}
Hope this helps.
CaKiwi
 
Sorry, I forgot the comma delimiter. Change the statement with the printf to
Code:
  if (j && j<length) printf substr($0,j+2) &quot;,&quot;
CaKiwi
 
CaKiwi, thanks for the assistance but I am getting errors on line 7 and 12 when i run: awk -f test.awk filename > flatfile

ERROR:

awk: syntax error near line 7
awk: illegal statement near line 7
awk: syntax error near line 12
awk: bailing out near line 12


I am using Sun Solaris 2.7 do you think this could be the problem?

Thanks,
EG22
 
Yes, the problem is awk on Solaris has not been updated to the Posix standard. But the supply nawk which you can use instead. CaKiwi
 
Follow - UP Question

I have another file with this format:

From MAILER-DAEMON Mon Oct 29 13:57:17 2001
Date: Mon, 29 Oct 2001 13:57:17 -0600 (CST)
From: Mail System Internal Data <MAILER-DAEMON@mdaisd1.mdacc.tmc.edu>
Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
X-IMAP: 0987177240 0000041141
Status: RO

This text is part of the internal format of your mail folder, and is not
a real message. It is created automatically by the mail system software.
If deleted, important folder data will be lost, and it will be re-created
with the data reset to initial values.

From s Mon Jun 21 20:22:59 1999
X-UIDL: bc6c08cb11850e26c65b10e0eea7ac01
Received: from rpi.mdacc.tmc.edu (rpi.mdacc.tmc.edu [143.141.44.41])
by mdaisd1.mdacc.tmc.edu (8.9.1b+Sun/8.9.1) with SMTP id UAA15807
for <mdaccweb@mdaisd1>; Mon, 21 Jun 1999 20:22:54 -0500 (CDT)
Received: by rpisun2.mdacc.tmc.edu (SMI-8.6/SMI-SVR4)
id UAA26441; Mon, 21 Jun 1999 20:28:38 -0500
Date: Mon, 21 Jun 1999 20:28:38 -0500
Message-Id: <199906220128.UAA26441@rpi.tmc.edu>
To: ilfrdb1@tmc.com
From: lade@yye.net
Subject: Information Line:882199202838DRD
Content-Length: 1236
Status: RO
X-Status:
X-Keywords:
X-UID: 1

Supportive Programs Form

Submitted Date: 06/21/99
Submitted Time: 21:49:29

Confirmation Identification Number: 062199214929FSN

User Information:

First Name.............: YVONNE
Last Name..............: JONES
Address................: 2301 DUBLIN CIRCLE
City...................:
State..................: TX
ZIP....................: 77581
Country................: UNITED STATES
Phone..................: 281/481-4006
Email..................: EMCEYVONNE@AOL.COM
Sex....................: Female
Primary Cancer.........: Breast

Talk to Patient........: YES
Support Groups.........: YES
Warmnet................: YES

Additional Information:
This is a very short version.

Text information goes here when they submit some of their stuff. It can get to a paragraph sometimes. So, it needs to
fit on the file.


Detected Browser Information:

Users IP#..............: 152.201.243.249
Users Hostname.........: 98C9F3F9.ipt.aol.com
Users Agent............: Mozilla/4.0 (compatible; MSIE 4.01; AOL 4.0; Windows 98)

From s Mon Jun 21 20:22:59 1999
X-UIDL: bc6c08cb11850e26c65b10e0eea7ac01
Received: from rpi.mdacc.tmc.edu (rpi.mdacc.tmc.edu [143.141.44.41])
by mdaisd1.mdacc.tmc.edu (8.9.1b+Sun/8.9.1) with SMTP id UAA15807
for <mdaccweb@mdaisd1>; Mon, 21 Jun 1999 20:22:54 -0500 (CDT)
Received: by rpisun2.mdacc.tmc.edu (SMI-8.6/SMI-SVR4)
id UAA26441; Mon, 21 Jun 1999 20:28:38 -0500
Date: Mon, 21 Jun 1999 20:28:38 -0500
Message-Id: <199906220128.UAA26441@rpi.tmc.edu>
To: ilfrdb1@tmc.com
From: lade@yye.net
Subject: Information Line:882199202838DRD
Content-Length: 1236
Status: RO
X-Status:
X-Keywords:
X-UID: 1

Supportive Programs Form

Submitted Date: 06/21/99
Submitted Time: 21:49:29

Confirmation Identification Number: 062199214929FSN

User Information:

First Name.............: Joe
Last Name..............: JONES
Address................: 24444 DUBLIN CIRCLE
City...................:
State..................: TX
ZIP....................: 77581
Country................: UNITED STATES
Phone..................: 281/481-4006
Email..................: EM44E@AOL.COM
Sex....................: Female
Primary Cancer.........: Breast

Talk to Patient........: YES
Support Groups.........: YES
Warmnet................: YES

Additional Information:
There is text here

Text information goes here when they submit some of their stuff. It can get to a paragraph sometimes. So, it needs to
fit on the file.

Detected Browser Information:

Users IP#..............: 152.201.243.249
Users Hostname.........: 98C9F3F9.ipt.aol.com
Users Agent............: Mozilla/4.0 (compatible; MSIE 4.01; AOL 4.0; Windows 98)

There are two problem:
1. I only want the text starting with &quot;To: ilfrdb1@tmc.com&quot;
all the way down to &quot;Users Agent&quot; going to a comma delimitted file file

##################

OUTPUT DESIRED:

ilfrdb1@tmc.edu,lade@yye.net,informationline:882199202838DRD,RO,,,1,06/21/99,21:49.19,062199214929FSN
YVONNE,JONES, 2301 DUBLIN CIRCLE,,TX,77581,UNITED STATES,281/481-4006,EMCEYVONNE@AOL.COM,FEMALE,BREAST,
YES,YES,YES,This is a very short version. Text information goes here when they submit some of their stuff. It can get to a paragraph sometimes. So, it needs to
fit on the file.,52.21.243,249,98C9F3F9.ipt.aol.com,Mozilla/4.0 (compatible; MSIE 4.01; AOL 4.0; Windows 98)

ilfrdb1@tmc.edu,lade@yye.net,informationline:882199202838DRD,RO,,,1,06/21/99,21:49.19,062199214929FSN
JOE,JONES, 2301 DUBLIN CIRCLE,,TX,77581,UNITED STATES,281/481-4006,EMCEYVONNE@AOL.COM,FEMALE,BREAST,
YES,YES,YES,This is a very short version. Text information goes here when they submit some of their stuff. It can get to a paragraph sometimes. So, it needs to
fit on the file.,152.201.43,49,98C9F3F9.ipt.aol.com,Mozilla/4.0 (compatible; MSIE 4.01; AOL 4.0; Windows 98)

The problem is that sometimes there are entries without:

----------------------------------------
&quot;From MAILER-DAEMON Mon Oct 29 13:57:17 2001
Date: Mon, 29 Oct 2001 13:57:17 -0600 (CST)
From: Mail System Internal Data <MAILER-DAEMON@mdaisd1.mdacc.tmc.edu>
Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
X-IMAP: 0987177240 0000041141
Status: RO

This text is part of the internal format of your mail folder, and is not
a real message. It is created automatically by the mail system software.
If deleted, important folder data will be lost, and it will be re-created
with the data reset to initial values.&quot;


---------------------------------------
WHICH I DO NOT CARE FOR.

* THE OTHER POINT TO THIS REQUEST IS THE SIZE of the file which is 63MB long. I get errors trying to run awk with such a big file.

Thank you,

EG22
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top