Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sort data in txt file by date and time
#1
Here I am with a new request for help.
I have a txt file in Desktop directory named ARCHIVIO.TXT with the following data :

<DATE:8>20190313 <TIME:6>221015 <ID:2>MY <RX:3>MTS ....(follow are data in the same line)
<DATE:8>20190314 <TIME:6>081030 <ID:2>MY <RX:2>MT ....(follow are data in the same line)
<DATE:8>20190312 <TIME:6>121015 <ID:2>MY <RX:3>MTH ....(follow are data in the same line)
<DATE:8>20190312 <TIME:6>000000 <ID:2>MY <RX:4>MTGF ....(follow are data in the same line)
<DATE:8>20190312 <TIME:6>121016 <ID:2>MY <RX:3>SSH ....(follow are data in the same line
<DATE:8>20190315 <TIME:6>000020 <ID:2>MY <RX:3>ARB ....(follow are data in the same line)
<DATE:8>20190310 <TIME:6>001030 <ID:2>MY <RX:3>MTR ....(follow are data in the same line)
<DATE:8>20190314 <TIME:6>000020 <ID:2>MY <RX:3>MTH ....(follow are data in the same line)
( follow others lines )

I need to obtein a new file (named PERSONAL.TXT) with DATE and TIME in descending order (from oldest to most recent)

<DATE:8>20190310 <TIME:6>001030 <ID:2>MY <RX:3>MTR ....(follow others data in the same line)
<DATE:8>20190312 <TIME:6>000000 <ID:2>MY <RX:4>MTGF ....(follow others data in the same line)
<DATE:8>20190312 <TIME:6>121015 <ID:2>MY <RX:3>MTH ....(follow others data in the same line)
<DATE:8>20190312 <TIME:6>121016 <ID:2>MY <RX:3>SSH ....(follow others data in the same line
<DATE:8>20190313 <TIME:6>221015 <ID:2>MY <RX:3>MTS ....(follow others data in the same line)
<DATE:8>20190314 <TIME:6>000020 <ID:2>MY <RX:3>MTH ....(follow are data in the same line)
<DATE:8>20190314 <TIME:6>081030 <ID:2>MY <RX:2>MT ......(follow others data in the same line)
<DATE:8>20190315 <TIME:6>000020 <ID:2>MY <RX:3>ARB ....(follow others data in the same line)
( follow others lines )

Note: The number after DATE it's mean the number of the digit of the date (YYYYMMDD).
The number after TIME it's mean the number of the digit of the time (HHMMSS).
These numbers for these fields are alway the same ( 8 for DATE and 6 for TIME ).

Actually I convert the TXT file to CSV format and using Excel I can arrange a descending order.
After I convert again in txt format.

Surely there is a simple way using QM !

Can I get help? ... I tried to search the forum but I didn't find anything like it.

Thanks a lot !
#2
Code:
Copy      Help
str s.getfile("$desktop$\ARCHIVIO.TXT")
ARRAY(str) a=s
a.sort
s=a
s.setfile("$desktop$\PERSONAL.TXT")
#3
QM code, too powerful
#4
Hello Kevin
it's perfect... Thanks.

I need to study some more about about ARRAY !
#5
Kevin,

Using the clipboard instead of writing to files works with sorting text alphabetically but only if text is all lowercase or all capitalized. Is there any way to make it ignore case? I.e.:

Before:
Elza
buddy
mother
child

After:
buddy
child
Elza
mother

Macro clipboard
Code:
Copy      Help
str s.getclip
ARRAY(str) a=s
a.sort
s=a
s.setclip
#6
Code:
Copy      Help
str s.getclip
ARRAY(str) a=s
a.sort(2)
s=a
s.trim
s.setclip
#7
Great, thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)