awk 함수, 'myArr' 근처에 예기치 않은 구문 오류가 있습니다.

awk 함수, 'myArr' 근처에 예기치 않은 구문 오류가 있습니다.

내 간단한 함수가 "'myArr' 근처에 예기치 않은 구문 오류"를 일으키는 이유가 무엇인지 잘 모르겠습니다. 배열, 조회 키 값, 광고 항목 부분 이름을 매개변수로 사용합니다. 배열의 각 행은 ","로 구분된 문자열입니다. 첫 번째 문자열이 조회 키 값과 같은지 확인 중입니다. 그렇다면 해당 행을 출력 파일에 인쇄하고 awk 스크립트 외부의 함수를 사용하고 있습니다.

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")

            }
        }       








}'

답변1

이것은 awk 함수를 awk 코드로 옮기는 것 외에는 실제로 대답이 아닙니다. 추가 제안: 다음과 같이 좀 더 관용적인 awk 스타일로 코드를 작성하겠습니다.

awk -v authFile="$Authorization" \
    -v lineFile="$LineItem" \
    -v modFile="$ModifierCode" \
    -v output="$OUTFILE" \
'
    BEGIN  {
        # build the file list dynamically
        ARGV[ARGC++] = authFile
        ARGV[ARGC++] = lineFile
        ARGV[ARGC++] = modFile
    }

    function LineItems(myArr, AuthKey, LIsection) {
        for (LI in myArr) { 
            split(myArr[LI], a, ",")
            if (a[1] == AuthKey) {
                print LIsection"," myArr[LI] > output
            }
        }
    }

    FILENAME == authFile {
        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
    }

    FILENAME == lineFile {
        split($0,li,",")

        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
    }

    FILENAME == modFile { 
        split($0,mi,",")

        Mod_Auth_num = mi[4]
        Modifier_ID = mi[5]
        modifier_code = mi[7]

        ModifierCode_Arr[FNR] = Mod_Auth_num","Modifier_ID","modifier_code
    }

    END { 
        for (key in Authorization_Arr) {   
            if (key != "authorization_num") { 
                print "SASH," Authorization_Arr[key] > output

                LineItems(LineItem_Arr, key, "SPLI")
                LineItems(ModifierCode_Arr, key, "SPLI_Mod")
            }
        }       
    }
'

관련 정보