I am not sure why my simple function causes "Syntax error near unexpected 'myArr,'. I taking an array, lookup key value and a line item section name as arguments. Each row in the array is "," delimited string. I am checking if the first string equals the look key value. If it does I will print out the row to my output file. I am using awk. I have the function outside of the awk being script.
Authorization="Authorization.csv";
LineItem="LineItem.csv";
ModifierCode="ModifierCode.csv";
OUTFILE="output.csv"
function LineItems(myArr, AuthKey, LIsection){
for (LI in myArr)
{
split(myArr[LI], a, ",")
if (a[1] == AuthKey)
{
print LIsection"," myArr[LI] > "output.csv"
}
}
}
awk 'BEGIN { NR>1
while (getline < "'"$Authorization"'" )
{
split($0,ft,",");
Auth_num=ft[4];
request_date=ft[5];
status=ft[8];
state=ft[9];
state_date=ft[10];
request_source=ft[12];
method=ft[13];
level_of_urgency=ft[17];
urgency_requested_by=ft[18];
primary_diagnosis=ft[19];
primary_code=ft[20];
continuity_of_care=ft[21];
court_ordered=ft[22];
member_eligibility_and_benifits_verified=ft[23];
single_case_agreement=ft[24];
case_name=ft[25];
requesting_provider=ft[28];
requesting_provider_id=ft[29];
requesting_provider_npi=ft[30];
requesting_provider_phone=ft[32];
requesting_provider_phone_ext=ft[34];
requesting_provider_fax_number=ft[36];
Authorization_Arr[Auth_num]=Auth_num","request_date","status","state","state_date","request_source","method","level_of_urgency","urgency_requested_by","primary_diagnosis","primary_code","continuity_of_care","court_ordered","member_eligibility_and_benifits_verified","single_case_agreement","case_name","requesting_provider","requesting_provider_id","requesting_provider_npi","requesting_provider_phone","requesting_provider_phone_ext","requesting_provider_fax_number;
}
close("'"$Authorization"'");
LineItCounter=0;
while (getline < "'"$LineItem"'")
{
split($0,li,",");
LineItCounter=LineItCounter+1
LI_Auth_num=li[4];
LI_ID=li[5];
line_item_number=li[6];
requested_from_date=li[7];
requested_to_date=li[8];
type=li[9];
requested_date=li[10];
determination_due_date=li[12];
service_type=li[13];
status=li[14];
level_of_urgency=li[15];
urgency_requested_by=li[16];
primary_procedure=li[18];
code=li[19];
applied_eligibility=li[20];
servicing_provider=li[21];
provider_id=li[22];
npi=li[23];
in_network=li[24];
servicing_provider_phone=li[26];
place_of_service=li[28];
comments=li[29];
method=li[30];
out_of_network_reason=li[31];
preliminary_requested_units=li[33];
request_source=li[34];
determined_from_date=li[35];
determined_to_date=li[36];
determination=li[37];
requested_units=li[39];
recommended_units=li[40];
determined_units=li[41];
type_of_decision=li[42];
LineItem_Arr[LI_ID]=LI_Auth_num","LI_ID","line_item_number","requested_from_date","type","requested_date","determination_due_date","service_type","status","level_of_urgency","urgency_requested_by","primary_procedure","code","applied_eligibility","servicing_provider","provider_id","npi","in_network","servicing_provider_phone","place_of_service","comments","method","out_of_network_reason","preliminary_requested_units","request_source","determined_from_date","determined_to_date","determination","requested_units","recommended_units","determined_units","type_of_decision;
}
close("'"$LineItem"'");
Modcounter=0;
while (getline < "'"$ModifierCode"'")
{
split($0,mi,",");
Modcounter=Modcounter+1
Mod_Auth_num=mi[4];
Modifier_ID=mi[5];
modifier_code=mi[7];
ModifierCode_Arr[Modcounter]=Mod_Auth_num","Modifier_ID","modifier_code;
}
close("'"$ModifierCode"'");
for (key in Authorization_Arr)
{
if (key != "authorization_num")
{
print "SASH," Authorization_Arr[key] > "output.csv"
LineItems(LineItem_Arr,key"SPLI")
LineItems(ModifierCode_Arr,key,"SPLI_Mod")
}
}
}'
awk
and try again. No, I didn't review your stuff -- it's just that that error is from bash, not from awk.awk
, notbash
code. Paste it after the single quote, just before theBEGIN
block.while...
loop inside yourBEGIN
clause? That really makes little sense. TheBEGIN
clause is to set up variables, etc., before the mainawk
loop runs across its input.