ugly but it seems to work. I am sure others with better skills could improve it.
Code:
;delete the file
filedelete final.txt
;###################################################################
; below is the 'natural sorting' function
; from http://www.autohotkey.com/forum/viewtopic.php?t=35835
_LogicalSort(x,y,offset)
{
static RegEx := "S)(\D*)(\d*)(.*)"
Loop
{
RegExMatch(x, RegEx, x)
RegExMatch(y, RegEx, y)
if (x1 != y1)
return x1 < y1 ? -1 : 1
if (x2 != y2)
return x2 < y2 ? -1 : 1
if (x3 = "" || y3 = "")
break
x := x3
y := y3
}
if (x3 != "")
{
;x is "longer"
return 1
}
else if (y3 != "")
{
;y is "longer"
return -1
}
else
{
;equal - maintain original order (stable)
return -offset
}
}
; read each file and append to final file. add a number + "_" to each read line for sorting
Loop, Read, file1.txt , final.txt
{
fileappend, %a_index%_%A_LoopReadLine%`n,
}
Loop, Read, file2.txt , final.txt
{
fileappend, %a_index%_%A_LoopReadLine%`n,
}
Loop, Read, file3.txt , final.txt
{
fileappend, %a_index%_%A_LoopReadLine%`n,
}
Loop, Read, file4.txt , final.txt
{
fileappend, %a_index%_%A_LoopReadLine%`n,
}
Loop, Read, file5.txt , final.txt
{
fileappend, %a_index%_%A_LoopReadLine%`n,
}
; read the final file
FileRead, final_var, final.txt
; destroy the final file
filedelete final.txt
; sort the variable from fileread
sort, final_var,F_LogicalSort
; loop thru and strip out the number + "_" at the start of each line
loop, parse, final_var, `n, `r
{
sorted .= RegExReplace(a_loopfield,"^(\d+_)(.*)","$2") . "`n"
}
;recreate the final file
fileappend, %sorted%, final.txt
msgbox finished