Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Sorting non-REBOL data

 [1/4] from: swhite:ci:bloomington:mn:us at: 1-Mar-2010 10:22


I have to create a text file of 49-byte records (lines) in a fixed format, to create an interface between two systems. I build it in memory and it looks like the sample below. 122998 720095 100109 00006000 3 ACH 123472 541099 100109 00050216 1 201 123473 541099 100109 00047164 1 201 123534 527401 100109 00000777 1 201 123593 527401 100109 00024206 1 201 123606 548187 100109 00009111 0 COUPON ONLY 123611 548187 100109 00005221 0 COUPON ONLY 123638 551670 100109 00352098 1 101 Before I write it to disk, I want to sort it on that first six-digit number in positions 1-6. I looked up the documentation of "sort" and thought that the "skip" option is used for fixed-format lines, with the number after the data name being a number that indicates the size of the line. So I coded: sort/skip PYIMPORT-FILE 49 The script returns a message of "Invalid argument: 49." Is it possible to sort a fixed-format text file of non-REBOL data? Thank you. Steven White City of Bloomington 1800 W Old Shakopee Rd Bloomington MN 55431-3096 USA 952-563-4882 (voice) 952-563-4672 (fax) swhite-ci.bloomington.mn.us

 [2/4] from: dhsunanda:gma:il at: 1-Mar-2010 16:48


What you have, presumably, is a string like this: str: {122998 720095 100109 00006000 3 ACH 123472 541099 100109 00050216 1 201 123473 541099 100109 00047164 1 201 123534 527401 100109 00000777 1 201 123593 527401 100109 00024206 1 201 123606 548187 100109 00009111 0 COUPON ONLY 123611 548187 100109 00005221 0 COUPON ONLY 123638 551670 100109 00352098 1 101 } That is not directly sortable as it (in REBOL's eyes) is a single record. If you can be sure that the only newlines are the record separators, then you could convert the data into a REBOL block for sorting, and then convert it back to a string for writing: blk: parse/all str to-string newline sort blk ;; default sort will by on leading characters, as per your need str-2: copy "" foreach record blk [append str-2 join record newline] (There may be a better REBOL idiom for those last two lines: creating a string of records each separated by newline) Sunanda.

 [3/4] from: henrikmk:gm:ail at: 1-Mar-2010 17:50


On Mon, Mar 1, 2010 at 5:22 PM, Steven White <swhite-ci.bloomington.mn.us> wrote:
> I have to create a text file of 49-byte records (lines) in a fixed format, to create an interface between two systems. =A0I build it in memory and it looks like the sample below. > 122998 720095 100109 00006000 3 =A0 ACH
<<quoted lines omitted: 9>>
> The script returns a message of "Invalid argument: 49." > Is it possible to sort a fixed-format text file of non-REBOL data?
If you can do this _before_ formatting it as a fixed file, put the data in a block. Then you are able to sort it using /skip, /all and /compare. -- Regards, Henrik Mikael Kristensen

 [4/4] from: gregg:pointillistic at: 1-Mar-2010 10:09


Hi Steven, SW> I have to create a text file of 49-byte records (lines) in a SW> fixed format, to create an interface between two systems. I build SW> it in memory and it looks like the sample below. SW> SW> 122998 720095 100109 00006000 3 ACH SW> 123472 541099 100109 00050216 1 201 SW> 123473 541099 100109 00047164 1 201 It's not clear from the doc string for SORT, but it won't treat a string as records made up of characters. But never fear, you can use PARSE/ALL x "^/" to split your string into a block of records (or just build it up that way initially), sort that block, and then rebuild the string or use WRITE/LINES to save it. -- Gregg

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted