[英]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.