Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete line in text file and sort by date
#1
Hi ,
here again to ask your help.
I have a file named "FIRST.TXT" with about 20000 lines.
The original file have this structure (first line of data start after <eoh> and each line separated by <eor>

ADIF Export
<adif_ver:5>3.1.1
<created_timestamp:15>20210622 131000
<programid:6>WSJT-X
<programversion:5>2.4.0
<eoh>
<call:5>WA1TY <gridsquare:4>EM45 <mode:3>FT8 <rst_sent:3>+34 <rst_rcvd:3>+11 <qso_date:8>20210622 <time_on:6>131000 <qso_date_off:8>20210622 <time_off:6>131000 <band:3>15m <freq:9>21.091650 <station_callsign:5>W1WWW <my_gridsquare:4>EM21 <operator:5>w1www <eor>
<call:5>WA2TY <gridsquare:4>EM45 <mode:3>FT8 <rst_sent:3>+32 <rst_rcvd:3>+11 <qso_date:8>20210621 <time_on:6>111230 <qso_date_off:8>20210621 <time_off:6>111230 <band:3>15m <freq:9>21.091650 <station_callsign:5>W1WWW <my_gridsquare:4>EM21 <operator:5>w1www <eor>
<call:5>AA3TY <gridsquare:4>EM45 <mode:3>FT8 <rst_sent:3>+31 <rst_rcvd:3>+11 <qso_date:8>20210621 <time_on:6>101430 <qso_date_off:8>20210621 <time_off:6>101430 <band:3>15m <freq:9>21.091650 <station_callsign:5>W1WWW <my_gridsquare:4>EM21 <operator:5>w1www <eor>
<call:5>AD4TY <gridsquare:4>EM45 <mode:3>FT8 <rst_sent:3>+33 <rst_rcvd:3>+13 <qso_date:8>20210619 <time_on:6>131700 <qso_date_off:8>20210619 <time_off:6>131700 <band:3>15m <freq:9>21.091650 <station_callsign:5>W1WWW <my_gridsquare:4>EM21 <operator:5>w1www <eor>
<call:5>NN5TY <gridsquare:4>EM45 <mode:3>FT8 <rst_sent:3>+32 <rst_rcvd:3>+12 <qso_date:8>20210622 <time_on:6>131900 <qso_date_off:8>20210622 <time_off:6>131900 <band:3>15m <freq:9>21.091650 <station_callsign:5>W1WWW <my_gridsquare:4>EM21 <operator:5>w1www <eor>

FIRST QUESTION:

I must delete these lines in the title and create file SECOND.TXT
<adif_ver:5>3.1.1
<created_timestamp:15>20210622 131000
<programid:6>WSJT-X
<programversion:5>2.4.0

I do it with this macro:
str s.getfile("C:\Users\User\Desktop\LOG\first.txt")
s.findreplace("<ADIF_VER:5>3.1.1" "")
s.findreplace("<created_timestamp:15>20210622 131000" "")
s.findreplace("<programid:6>WSJT-X" "")
s.findreplace("<programversion:5>2.4.0" "")
out s
s.setfile("C:\Users\User\Desktop\LOG\second.txt")

Finally I have the words deleted but not the line.
What's the command for delete the line ? 
This is the actually resolt:

ADIF Export




<eoh>
<call:5>IK1TY <gridsquare:4>JN45 <mode:3>FT8 <rst_sent:3>+34 <rst_rcvd:3>+11 <qso_date:8>20210622 <time_on:6>131000 <qso_date_off:8>20210622 <time_off:6>131000 <band:3>15m <freq:9>21.091650 <station_callsign:5>W1WWW

As you see there is space between ADIF Export and <eoh> ..... I would like to not have this space with empty lines.
I'm looking for any command but I don't find it !

SECONDO QUESTION

Any help for a macro for index by date and time each <eoh> field and create a new file listed by date and time ?... The date and time are those following the <qso_date:8> entry and the <time_off:6> entry.

.... Hope to have a reply as soon as possible .... I start learning step by step but your help is primary !

Thank you !!!!
#2
for #1 a couple options
1A. -using replacerx and strings
Code:
Copy      Help
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
Code:
Copy      Help
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
Code:
Copy      Help
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)
#3
Hi Kevin,
I tested your solution with samples files and they work .... Thanks soo much !

I need for more help for a new macro but I open a specific thread.

Hope you can help me also for that.

Again ... thank you !!!!


Forum Jump:


Users browsing this thread: 2 Guest(s)