Probable awk question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Probable awk question
# 1  
Old 01-09-2013
Probable awk question

Hi,
I have a file in the following format.I need to sort the file according to 2nd column and third last column.
If all the claim numbers (second column) are paid. Third last column =P , they need to be printed in a file called as paid.txt
If all the claim numbers (second column) are denied. Third last column =D , they need to be printed in a file called as denied.txt
If the claim numbers (second column) are paid or denied (combination of both) Third last column =P OR Third last column =D , they need to be printed in a file called as mixture.txt

Input file
Code:
"S00079991"|"000171642730"|"904395"|"Y"|"20110425"|"599.0"|"428.23"|"041.19"|"276.51"|"427.31"|"428.0"|""|""|""|"2200"|"20110527"|""|"20110527"|"DRG"|"2200"|"Acute Care Inpatient R&B"|"P"|"F"|"I"
"S00079991"|"000171642730"|"904395"|"Y"|"20110425"|"599.0"|"428.23"|"041.19"|"276.51"|"427.31"|"428.0"|""|""|""|"2200"|"20110527"|""|"20110527"|"DRG"|"2100"|"Acute Care Inpatient R&B"|"D"|"F"|"I"
"S00723175"|"000145479460"|"603304"|"Y"|"20110727"|"719.40"|"244.9"|"272.9"|""|""|""|""|""|""|"6600"|"20110909"|""|"20110909"|"FEESC"|"6600"|"Venipuncture-Fac-MF POS"|"P"|"F"|"I"
"S00723175"|"000145479460"|"603304"|"Y"|"20110727"|"719.40"|"244.9"|"272.9"|""|""|""|""|""|""|"5840"|"20110909"|""|"20110909"|"FEESC"|"5840"|"Laboratory & Pathology-MF POS"|"P"|"F"|"I"
"S00723175"|"000145479460"|"603304"|"Y"|"20110727"|"719.40"|"244.9"|"272.9"|""|""|""|""|""|""|"5840"|"20110909"|""|"20110909"|"FEESC"|"5840"|"Laboratory & Pathology-MF POS"|"P"|"F"|"I"
"S00723175"|"000145479460"|"603304"|"Y"|"20110727"|"719.40"|"244.9"|"272.9"|""|""|""|""|""|""|"5840"|"20110909"|""|"20110909"|"FEESC"|"5840"|"Laboratory & Pathology-MF POS"|"P"|"F"|"I"
"S00543343"|"000147103900"|"695270"|"Y"|"20081006"|"585.6"|"V56.0"|"041.9"|"285.21"|"286.9"|"588.81"|"588.89"|"V05.3"|""|"1400"|"20110114"|""|"20110114"|"PCTBI"|"1400"|"Dialysis"|"D"|"F"|"I"
"S00543343"|"000147103900"|"695270"|"Y"|"20081006"|"585.6"|"V56.0"|"041.9"|"285.21"|"286.9"|"588.81"|"588.89"|"V05.3"|""|"1400"|"20110114"|""|"20110114"|"PCTBI"|"1400"|"Dialysis"|"D"|"F"|"I"
"S00543343"|"000147103900"|"695270"|"Y"|"20081006"|"585.6"|"V56.0"|"041.9"|"285.21"|"286.9"|"588.81"|"588.89"|"V05.3"|""|"1400"|"20110114"|""|"20110114"|"PCTBI"|"1400"|"Dialysis"|"D"|"F"|"I"
"S00543343"|"000147103900"|"695270"|"Y"|"20081006"|"585.6"|"V56.0"|"041.9"|"285.21"|"286.9"|"588.81"|"588.89"|"V05.3"|""|"1400"|"20110114"|""|"20110114"|"PCTBI"|"1400"|"Dialysis"|"D"|"F"|"I"

Output files would look something like this
Paid.txt
Code:
"S00723175"|"000145479460"|"603304"|"Y"|"20110727"|"719.40"|"244.9"|"272.9"|""|""|""|""|""|""|"6600"|"20110909"|""|"20110909"|"FEESC"|"6600"|"Venipuncture-Fac-MF POS"|"P"|"F"|"I"
"S00723175"|"000145479460"|"603304"|"Y"|"20110727"|"719.40"|"244.9"|"272.9"|""|""|""|""|""|""|"5840"|"20110909"|""|"20110909"|"FEESC"|"5840"|"Laboratory & Pathology-MF POS"|"P"|"F"|"I"
"S00723175"|"000145479460"|"603304"|"Y"|"20110727"|"719.40"|"244.9"|"272.9"|""|""|""|""|""|""|"5840"|"20110909"|""|"20110909"|"FEESC"|"5840"|"Laboratory & Pathology-MF POS"|"P"|"F"|"I"
"S00723175"|"000145479460"|"603304"|"Y"|"20110727"|"719.40"|"244.9"|"272.9"|""|""|""|""|""|""|"5840"|"20110909"|""|"20110909"|"FEESC"|"5840"|"Laboratory & Pathology-MF POS"|"P"|"F"|"I"

Denied.txt
Code:
"S00543343"|"000147103900"|"695270"|"Y"|"20081006"|"585.6"|"V56.0"|"041.9"|"285.21"|"286.9"|"588.81"|"588.89"|"V05.3"|""|"1400"|"20110114"|""|"20110114"|"PCTBI"|"1400"|"Dialysis"|"D"|"F"|"I"
"S00543343"|"000147103900"|"695270"|"Y"|"20081006"|"585.6"|"V56.0"|"041.9"|"285.21"|"286.9"|"588.81"|"588.89"|"V05.3"|""|"1400"|"20110114"|""|"20110114"|"PCTBI"|"1400"|"Dialysis"|"D"|"F"|"I"
"S00543343"|"000147103900"|"695270"|"Y"|"20081006"|"585.6"|"V56.0"|"041.9"|"285.21"|"286.9"|"588.81"|"588.89"|"V05.3"|""|"1400"|"20110114"|""|"20110114"|"PCTBI"|"1400"|"Dialysis"|"D"|"F"|"I"
"S00543343"|"000147103900"|"695270"|"Y"|"20081006"|"585.6"|"V56.0"|"041.9"|"285.21"|"286.9"|"588.81"|"588.89"|"V05.3"|""|"1400"|"20110114"|""|"20110114"|"PCTBI"|"1400"|"Dialysis"|"D"|"F"|"I"

Mixture.txt
Code:
"S00079991"|"000171642730"|"904395"|"Y"|"20110425"|"599.0"|"428.23"|"041.19"|"276.51"|"427.31"|"428.0"|""|""|""|"2200"|"20110527"|""|"20110527"|"DRG"|"2200"|"Acute Care Inpatient R&B"|"P"|"F"|"I"
"S00079991"|"000171642730"|"904395"|"Y"|"20110425"|"599.0"|"428.23"|"041.19"|"276.51"|"427.31"|"428.0"|""|""|""|"2200"|"20110527"|""|"20110527"|"DRG"|"2100"|"Acute Care Inpatient R&B"|"D"|"F"|"I"

Ane help will be greatly appreciated!

Last edited by Scrutinizer; 01-09-2013 at 04:15 PM.. Reason: Changed icode tags to code tags
# 2  
Old 01-09-2013
try:
Code:
sort -t"|" -k 2,22 input_file | awk -F"|" '
$(NF-2) ~ /"P"/ {p[$2]=$0; print $0 > "Paid.txt"}
$(NF-2) ~ /"D"/ {d[$2]=$0; print $0 > "Denied.txt"}
p[$2] && d[$2] {print p[$2]"\n"d[$2] > "Mixture.txt"}'


Last edited by rdrtx1; 01-09-2013 at 05:05 PM..
This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 01-09-2013
Code:
awk -F\| '{
   if ($(NF-2) == "\"P\"")      p[$2] = (p[$2] ? p[$2] RS $0 : $0)
   else if ($(NF-2) == "\"D\"") d[$2] = (d[$2] ? d[$2] RS $0 : $0)
} END {
   for (i in p) {
       if (i in d) print p[i] RS d[i] >> "mixture.txt"
       else print p[i] >> "paid.txt"
   }
   for (j in d)
       if (!(j in p)) print d[j] >> "denied.txt"
}' file

This User Gave Thanks to shamrock For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk question : system output to awk variable.

Hi Experts, I am trying to get system output to capture inside awk , but not working: Please advise if this is possible : I am trying something like this but not working, the output is coming wrong: echo "" | awk '{d=system ("date") ; print "Current date is:" , d }' Thanks, (5 Replies)
Discussion started by: rveri
5 Replies

2. Shell Programming and Scripting

awk question

Hi experts, I have a simple problem .I have a awk file which reads data from the text file, into a variable.There are some entries in the file which are duplicate.Is there a way in awk to eliminate the duplicate entries. PLANNAME = substr($0,228,60) printf("\t Please keep this notice. It... (6 Replies)
Discussion started by: nua7
6 Replies

3. Shell Programming and Scripting

Another AWK question

Helo Experts I have bunch of lines like below : I'd like to convert every "non zero-like digit" so it multiplied by 8. The results should be like : I know awk can solve this , but I'm just a newbie. TIA (7 Replies)
Discussion started by: rk4k
7 Replies

4. UNIX for Dummies Questions & Answers

Basic awk question...getting awk to act on $1 of the command itself

I have a script problem that I am not able to solve due my very limited understanding of unix/awk. This is the contents of test.sh awk '{print $1}' From the prompt if I enter: ./test.sh Hello World I would expect to see "Hello" but all I get is a blank line. Only then if I enter "Hello... (2 Replies)
Discussion started by: JasonHamm
2 Replies

5. Shell Programming and Scripting

awk question

Lets say I have program named "programA" and you run like below programA uniquecallerID somefilename which will grep out something like this ------------somefilename----------- asdfasdfasdf asdfasdf callIDabc asdfd sdfd callIDabc sdrsdf sdfasdfsadfdsf asdfasdfasdfasdfasdf (6 Replies)
Discussion started by: hankooknara
6 Replies

6. Shell Programming and Scripting

Question in awk

Dear All, How can we sort using awk?Is there anything by default Please help me. Regards, Sukumar (4 Replies)
Discussion started by: jerome Sukumar
4 Replies

7. Shell Programming and Scripting

AWK question?

I have question about awk if someone can help me here. I want to find a string (file has just one row) and then get the position of the column. let say i have 4 columns a b c d Look for b and somehow get the column position in this case b is at $2 script doesn't know what is the position... (9 Replies)
Discussion started by: J_ang
9 Replies

8. Shell Programming and Scripting

awk question

I have the following error: ls -lt | awk 'BEGIN NR > 1 { print $2, $9 }' Syntax Error The source line is 1. The error context is BEGIN >>> NR <<< > 1 { print $2, $9 } awk: 0602-500 Quitting The source line is 1. What I want to do is ls a directory, skip the first... (3 Replies)
Discussion started by: lesstjm
3 Replies
Login or Register to Ask a Question