for #1 a couple options
1A. -using replacerx and strings
1B. -using an array
for #2 try this
1A. -using replacerx and strings
str s.getfile("$desktop$\LOG\FIRST.txt")
s.replacerx("<adif_ver:5>3.1.1([\s\S]*)<programversion:5>2.4.0" "")
;s.replacerx("(?:(?:(?!\n)\s)*\n){2,}" "[]");; remove blank lines
s.replacerx("(?m)^\s+");;remove blank lines
out s
1B. -using an array
str s.getfile("$desktop$\LOG\FIRST.txt")
ARRAY(str) a=s
int i; for(i a.len-1 -1 -1) if(i>0 and i<5) a.remove(i)
s=a
s.rtrim
out s
for #2 try this
str s.getfile("$desktop$\LOG\FIRST.txt")
ARRAY(str) a b; a=s
int i; for(i a.len-1 -1 -1) if(i<6) a.remove(i)
a.sort(2 sub.Callback_ARRAY_sort)
s=a
if(s.len) s.fix(s.len-2)
s- "ADIF Export[]<eoh>[]"
out s
s.setfile("$desktop$\LOG\second.txt")
#sub Callback_ARRAY_sort
function# param str&a str&b
str s1 s2 s3 s4
findrx(a "\<qso_date:8\>(.+?) \<" 0 1 s1 1)
findrx(b "\<qso_date:8\>(.+?) \<" 0 1 s2 1)
if(StrCompare(s1 s2)=0)
,findrx(a "\<time_off:6\>(.+?) \<" 0 1 s3 1)
,findrx(b "\<time_off:6\>(.+?) \<" 0 1 s4 1)
,ret StrCompare(s3 s4 1)
else
,ret StrCompare(s1 s2 1)