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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lining up column output correctly 1

Status
Not open for further replies.

dougout

MIS
Jul 27, 2001
5
0
0
US
Hi All,
First time post. New to AWK. How can I alter this script to prevent the PID from printing until the FT1 and possibly the PR1 has executed? Right now the data from the PID prints and its associated FT1 data prints on the follwing line. I'm always one step behind with the FT1 and PR1 data. Any help would be appreciated.

awk '
BEGIN {
FS = "|"
printf "%8s%8s%17s%9s%8s%9s%7s\n",
"Account", "Name", "Svc Date", "T code", "HCPCS", "Modif", "Qty"
printf " -------- ---------- --------
------ ----- -----" " ---\n"
}

/^PID\|/ {
Acct = $19
Name = $6
}

/^FT1\|/ {
{printf "%9s %.10s %9s %8s %5s %7s
%7s\n", Acct, Name, SvcDate, Tcode, HCPCS, Modif, Qty }

SvcDate = $5
Tcode = $8
Qty = $11

HCPCS = ""
Modif = ""
}

/^PR1\|/ {
if ($7 == "M")
{Modif = $4}
else
{HCPCS = substr($4,1,5)}
}

END {
{printf "%9s %.10s %9s %8s %5s %7s %7s\n",
Acct, Name, SvcDate, Tcode, HCPCS, Modif, Qty }
}'
 

Would moving the printf to the beginning of the PID section and setting of HCPCS and Modif to the end of the PID section do it? If not, post some sample data and the output you want.

CaKiwi
 
CaKiwi,
This is the output now:

Account Name Svc Date T code HCPCS
-------- ---------- -------- ------ -----
0012121 AAAAJOEE^V
00131313 LLLIKEE^BA 20010418 677777 83111
00989898 WARDYYJON^ 20010420 711111
00989898 WARDYYJON^ 20010424 309
00989898 WARDYYJON^ 20010424 632323


This would be the desired output:

Account Name Svc Date T code HCPCS
-------- ---------- -------- ------ -----
00121212 AAAAJOEE^V 20010418 677777 83111
00131313 LLLIKEE^BA 20010420 711111
00989898 WARDYYJON^ 20010424 309
00989898 WARDYYJON^ 20010424 632323


This is a sample of the data:
MSH|^~\&|BILLING|LOTUS|WORDPAD||20010709003049||DFT^P03|1|D|2.3
EVN|P03|20010709003049||
PID|1||000000||AAAAJOEE^VICTOR|||||6||||||||00121212|011112222
FT1||||20010418|||677777|||10|||IFLAB|||||||||
PR1|1|C4|83111^Myaclencin|||P||||||||1
MSH|^~\&|BILLING|LOTUS|WORDPAD||20010709003050||DFT^P03|2|D|2.3
EVN|P03|20010709003050||
PID|1||000000||LLLIKEE^BA|||||5||||||||00131313|132212212
FT1||||20010420|||711111|||1|||IFLAB|||||||||
MSH|^~\&|BILLING|LOTUS|WORDPAD||20010709003050||DFT^P03|3|D|2.3
EVN|P03|20010709003050||
PID|1||000000||WARDYYJON^|||||5||||||||00989898|454323411
FT1||||20010424|||309|||1|||IFLAB|||||||||
FT1||||20010424|||632323|||1|||IFLAB|||||||||


Thanks in advance for your insight,
Dougout
 
Dougout,

The program below will give you the results you want for the data you supplied, but I suspect that it will not be what you want for more general data. It seems that the PID record starts a new series of records for an account, the FT1 records are a series of transactions for that account and the PR1 record is some additional information for the account. If this analysis is correct, my question is how many PR1 can there be for each account and where can they occur.

BEGIN {
FS = "|"
printf "%8s%8s%17s%9s%8s%9s%7s\n",
"Account", "Name", "Svc Date",
"T code", "HCPCS", "Modif", "Qty"
printf " -------- ---------- -------- ------ ----- ----- ---\n"
}

/^PID\|/ {
Acct = $19
Name = $6
}

/^FT1\|/ {
SvcDate = $5
Tcode = $8
Qty = $11
if (flag)
printf "%9s %.10s %9s %8s %5s %7s %7s\n",
Acct,Name,SvcDate,Tcode,HCPCS,Modif,Qty

HCPCS = ""
Modif = ""
}

/^PR1\|/ {
if ($7 == "M")
Modif = $4
else
HCPCS = substr($4,1,5)
if (!flag) {
printf "%9s %.10s %9s %8s %5s %7s %7s\n",
Acct,Name,SvcDate,Tcode,HCPCS,Modif,Qty
HCPCS = ""
Modif = ""
flag = 1
}
}

CaKiwi
 
CaKiwi,
A sample breakdown of a message is as follows:

MSH
EVN
PID
FT1
FT1
PR1
FT1
PR1
PR1
FT1

The MSH starts a new series of records for an account. No data taken from the MSH or EVN segments. The PR1 can only occur after the FT1. PR1 is optional, or can occur up to 2 times (max of 2), if available. No limits on the FT1 segments for a account.

Thanks for your assistance,
Dougout

 
How about this?

BEGIN {
FS = "|"
printf "%8s%8s%17s%9s%8s%9s%7s\n",
"Account", "Name", "Svc Date",
"T code", "HCPCS", "Modif", "Qty"
printf " -------- ---------- -------- ------ ----- ----- ---\n"
}

/^PID\|/ {
if (flag)
printf "%9s %.10s %9s %8s %5s %7s %7s\n",
Acct,Name,SvcDate,Tcode,HCPCS,Modif,Qty
flag = 0
Acct = $19
Name = $6
}

/^FT1\|/ {
if (flag)
printf "%9s %.10s %9s %8s %5s %7s %7s\n",
Acct,Name,SvcDate,Tcode,HCPCS,Modif,Qty
flag = 1
SvcDate = $5
Tcode = $8
Qty = $11

HCPCS = ""
Modif = ""
}

/^PR1\|/ {
if ($7 == "M")
Modif = $4
else
HCPCS = substr($4,1,5)
}
END {
printf "%9s %.10s %9s %8s %5s %7s %7s\n",
Acct,Name,SvcDate,Tcode,HCPCS,Modif,Qty
}

CaKiwi
 
CaKiwi,
That did the trick! Thank you and have a great week!

Dougout
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top