I have a file with records such as:
111112 4000000001 01/01/13 13:05
111112 4000000002 02/02/13 13:05
111112 4000000003 03/03/13 13:05
111113 4000000004 04/01/13 07:05
111113 4000000005 05/01/13 10:05
111113 4000000006 06/01/13 17:05
111114 4000000007 06/01/13 18:05
111114 4000000008 06/01/13 19:05
111114 4000000009 06/01/13 20:05
1st column is an customer id, 2nd column is an acct. no.
I would like it in this format:
111112,4000000001,4000000002,4000000003
111113,4000000005,4000000005,4000000006
111114,4000000007,4000000008,4000000009
I have this script:
BEGIN { RS = "\n"; FS = " "}
{
prev = ""
oneof = ""
print "mrn: ", $1
print "acct: ", $2
print "admit date: ", $3
print "admit time: ", $4
print ""
$1!=prev
{
prev = $1
oneof = ""
}
if ( $1 && $1 == prev )
{
oneof=oneof$1","$2","
print "oneof: ", oneof
next
}
}
I get the following output:
111112,4000000001, and so on
I'm messing up on my logic. prev is supposed to keep track of the current customer id as mrn changes. As long as prev equals mrn you concatenate all the accounts. When the customer id changes, change prev to the new mrn then start concatenation again. Maybe someone can point me in the right direction to get the correct format.
111112 4000000001 01/01/13 13:05
111112 4000000002 02/02/13 13:05
111112 4000000003 03/03/13 13:05
111113 4000000004 04/01/13 07:05
111113 4000000005 05/01/13 10:05
111113 4000000006 06/01/13 17:05
111114 4000000007 06/01/13 18:05
111114 4000000008 06/01/13 19:05
111114 4000000009 06/01/13 20:05
1st column is an customer id, 2nd column is an acct. no.
I would like it in this format:
111112,4000000001,4000000002,4000000003
111113,4000000005,4000000005,4000000006
111114,4000000007,4000000008,4000000009
I have this script:
BEGIN { RS = "\n"; FS = " "}
{
prev = ""
oneof = ""
print "mrn: ", $1
print "acct: ", $2
print "admit date: ", $3
print "admit time: ", $4
print ""
$1!=prev
{
prev = $1
oneof = ""
}
if ( $1 && $1 == prev )
{
oneof=oneof$1","$2","
print "oneof: ", oneof
next
}
}
I get the following output:
111112,4000000001, and so on
I'm messing up on my logic. prev is supposed to keep track of the current customer id as mrn changes. As long as prev equals mrn you concatenate all the accounts. When the customer id changes, change prev to the new mrn then start concatenation again. Maybe someone can point me in the right direction to get the correct format.