繁体   English   中英

AHK:比较两个Txt文件

[英]AHK: Comparing Two Txt Files

因此,我正在为医生办公室开帐单,我们希望对三项检查是否确实开出了流感疫苗进行三重检查。 现在,我的AHK会在整个图表中检查ICD-10代码Z23之类的密钥,然后检查“流感”。 如果找到两者,则将患者的病历号添加到适合年龄的文本文件中,即65岁以上或65岁以下。还有一些带有10个插槽的纸张,我们手工记录了MRN,以进行仔细检查。 我想创建一个脚本来比较三个文件,即混合MRN(65+和<65)的MRN文件,如果在混合文件中找到了MRN,则应删除该行。 (我在该主题上进行了大量搜索,但每个人都建议使用库,这只会减慢我的程序的速度。)如果找不到该行,则应将该行留在主文件中以供我查看。 我无法弄清楚如何删除行,更不用说特定行了。 到目前为止,要相互检查文件,我有这个。 代替删除行,我将未开票的号码附加到第四个文本文件,但是最终,删除会更好。

FILENUM = 1
FILENU = 1
^L::
Loop
    {
    FileReadLine, MRN, E:\AHK & AHKS\flushot.txt, %LINENUM%
    If ErrorLevel
        {
        break
        }
    Else
        {
        Loop
            {
            FileReadLine, MRNc, E:\AHK & AHKS\Billed65+Flushots.txt, LINENU
            StringTrimRight, MRNc, 11
            If (MRN != MRNc)
                {
                LINENU++
                Match = 0
                }
            If (MRN == MRNc)
                Match = 1
            If ErrorLevel and Match = 0
                {
                FileAppend, MRN, E:\AHK & AHKS\Unbilledtester.txt
                LINENU = 1
                }
            If (Match = 1)
                GoTo Lab2

            }
        Lab2:
        Loop
            {
            FileReadLine, MRNc, E:\AHK & AHKS\BilledAdultFlushots.txt, LINENU
            StringTrimRight, MRNc, 11
            If (MRN != MRNc)
                {
                LINENU++
                Match = 0
                }
            If (MRN == MRNc)
                Match = 1
            If ErrorLevel and Match = 0
                FileAppend, MRN, E:\AHK & AHKS\Unbilledtester.txt
            If (Match = 1)
                GoTo Lab2

            }
        LINENUM++

        }
    }

更新!!!!!!!

好的,所以我抓取了您的代码,并且一直在尝试进行反向检查。 您在flushot.txt中检查“成人”和“高级”同花顺文本文件的关联数组,以查找MRNS,然后,如果找不到,则将它们添加到未开票。 以下是我为扭转这种情况所做的几种尝试,并检查了flushot.txt中成人和老年人中的MRN,如果找不到,请将其添加到一个名为notrecorded.txt的文件中,这样我就知道哪些人有同花顺以及谁没有记录下来(由初级保健提供者记录)。

FlushotsBilled()
{
Root_Dir            := "E:\AHK & AHKS"
fName_Input         := "flushot.txt"
fName_Backup        := "flushot_old.txt"
fName_Output        := "unbilled.txt"
fName_Billed_Adult  := "billedAdultFlushots.txt"
fName_Billed_Senior := "billed65+Flushots.txt"
fName_Billed_NR     := "notrecorded.txt"
fName_Mixed     := "mixrecord.txt"  

SetWorkingDir %Root_Dir%
FileDelete, %fName_Output%

AdultFlu   := {}
SeniorFlu  := {}
GivenFluA  := {}
GivenFluB  := {}
Mixed      := {}

Loop, Read, %fName_Mixed%
    Mixed[A_LoopReadLine] := True   

Loop, Read, %fName_Billed_Adult%
    {
    ;Loop, Parse, A_LoopReadLine, `t
    ;   AdultFlu[A_LoopField] := True
    AdultFlu[A_LoopReadLine] := True
        If !Mixed[A_LoopReadLine]
            FileAppend, %A_LoopReadLine%`n, %fName_Mixed%
    }

Loop, Read, %fName_Billed_Senior%
    {
    ;Loop, Parse, A_LoopReadLine, `t
    ;   SeniorFlu[A_LoopField] := True
    SeniorFlu[A_LoopReadLine] := True
        If !Mixed[A_LoopReadLine]
            FileAppend, %A_LoopReadLine%`n, %fName_Mixed%
    }

Loop, Read, %fName_Input% ;check flushot.txt for
    If !AdultFlu[SubStr(A_LoopReadLine, 1, InStr(A_LoopReadLine,"`t"))] && !SeniorFlu[SubStr(A_LoopReadLine, 1, InStr(A_LoopReadLine,"`t"))]
    ;If !AdultFlu[A_LoopReadLine] && !SeniorFlu[A_LoopReadLine] ;flushot is checking the associated arrays
        FileAppend, %A_LoopReadLine%`n, %fName_Output% ;if not found, stick it into unbilled.

Loop, Read, %fName_Input%
    GivenFluA[A_LoopReadLine] := True



/*  Loop, Read, %fName_Billed_Senior%
    If !Mixed[A_LoopReadLine]
        FileAppend, %A_LoopReadLine%`n, %fName_Mixed%

Loop, Read, %fName_Billed_Adult%
    If !Mixed[A_LoopReadLine]
        FileAppend, %A_LoopReadLine%`n, %fName_Mixed%

Loop, Read, %fName_Mixed%
    Mixed[A_LoopReadLine] := True
*/
Loop, Read, %fName_Mixed%
    If !GivenFluA[SubStr(A_LoopReadLine, 1, InStr(A_LoopReadLine,"`t"))] ;a_Loopreadline is a line in mixed. it is looking through flushot.txt for that line, if it's there, it's givenflua's index
        Loop, Read, %fName_Billed_NR%
            If !GivenFluA[A_LoopReadLine]
                FileAppend, %A_LoopReadLine%`n




/*
Loop, Read, %fName_Input% ;read flushot
    If Mixed[A_LoopReadLine] Contains A_LoopReadLine ;check to see if each line in flushot is in mixed
        GivenFluA[Mixed[A_LoopReadLine]] := True ;Mixed[A_LoopReadLine]

Loop, Read, %fName_Billed_NR%
    If !GivenFluA[A_LoopReadLine]
        FileAppend GivenFluA[%A_LoopReadLine%], %fName_Billed_NR%
*/

;if readline is in mixed, but not in flushot, check to see if it's in notrecorded, if not, append it

/*
Loop, Read, %fName_Mixed% ;open up the mixed record
    IfNotInString, A_LoopReadLine, GivenFluA[A_LoopReadLine] ;see if inside each line, we can find the lines from flushot.txt, if not
        ;GivenFluB[GivenFluA[A_LoopReadLine]] := True ;if not we give the line from inside flushot to another associative array
        GivenFluB[A_LoopReadLine] := True ;lets try this, put the value 

Loop, Read, %fName_Mixed%
    IfInString, A_LoopReadLine, GivenFluA[A_LoopReadLine]
        GivenFluB[A_LoopReadLine]

Loop, Read, %fName_Billed_NR% ;open up not recorded
    IfNotInString, A_LoopReadLine, GivenFluB[A_LoopReadLine] ;see if inside each line we can find that line from
        FileAppend, %A_LoopReadLine%`n, %fName_Billed_NR%
*/
}

我认为通过创建输出文件而不是删除行,您走上了正确的轨道。 文本文件通常被视为流,而不是固定记录长度的数据文件。 删除行容易出错并且效率不高; 您将不得不以某种方式压缩文件。

您的文件有多大? 如果只有几千名患者,我会将所有内容加载到关联数组中,以便我们可以使用键控查找。

程序

^L:: medical_run()

medical_run()
{
  root_dir            := "E:\AHK & AHKS"
  fname_input         := "flushot.txt"
  fname_backup        := "flushot_old.txt"
  fname_temp_output   := "Unbilledtester.txt"
  fname_billed_adult  := "billedAdultFlushots.txt"
  fname_billed_senior := "billed65+Flushots.txt"

  SetWorkingDir %root_dir%
  FileDelete %fname_output%

  adults    := {}
  seniors   := {}
  unmatched := {}

  loop READ, %fname_billed_adult%
    adults[A_LoopReadLine] := true

  loop READ, %fname_billed_senior%
    seniors[A_LoopReadLine] := true

  loop READ, %fname_input%
    if !adults[A_LoopReadLine] && !seniors[A_LoopReadLine]
      unmatched[A_LoopReadLine] := true

  for code,dummy in unmatched
    FileAppend %code%`n, %fname_output%

  FileMove %fname_input%, %fname_backup%
  FileMove %fname_temp_output%, %fname_input%
}

billedAdultFlushots.txt

101
102
103
104

billed65 + Flushots.txt

205
206
207
208

flushot.txt之前

301
101
103
302
205
301
207
103
303
301

之后的flushot.txt

301
302
303

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM