Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help to sort test file based on 4 fields

Status
Not open for further replies.

tweek

Technical User
May 1, 2002
15
US
Hi:

I have a file and want to sort it based on 4 fields. The file is to be sorted by field 1. While sorting on field 1, sort field 2 and while sorting on field 2, sort field 3 and so on. I am hoping I am explaining this right!!

Here is an example:
(The file is fixed length but for explanation is "|" delimited.)

Original File -
085460|000082506656|0298|0026
085460|000082506656|0298|0002
085460|000082506643|0298|0012
085460|000082506643|0298|0014
085459|000022000969|0364|0397
085459|000022000969|0364|0400
085459|000022000945|0364|0401
085459|000022000945|0364|0402
085469|000022001418|0362|0009
085469|000022001454|0362|0003
085469|000022001454|0362|0006
085469|000022001418|0362|0010

Sorted File -
085459|000022000945|0364|0401
085459|000022000945|0364|0402
085459|000022000969|0364|0397
085459|000022000969|0364|0400
085460|000082506643|0298|0012
085460|000082506643|0298|0014
085460|000082506656|0298|0002
085460|000082506656|0298|0026
085469|000022001418|0362|0009
085469|000022001418|0362|0010
085469|000022001454|0362|0003
085469|000022001454|0362|0006


I've looked through the threads for sorting but just can't piece what I've read and what I want to accomplish together.

Any help is greatly appreciated.

Thanks.
 
There are plenty of sort examples on and on these forums. Search for them (hint: sort array)

For this particular example...For you to sort all the fields you can always combine them on one single field, and then sort that particular field. This makes life easier.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
As the file is fixed length and the fields seem properly justify, simply sort with whole record as key.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
As the file is fixed length and the fields seem properly justified, simply sort with whole record as key.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks fredericofonseca/PHV...

These are not the only fields in the file. I only used this example to express the type of sort. In any case, I didn't even think of joining the fields together to make a unique field and then sort by the field.

Thanks again.
 
A starting point:
strFile = "\path\to\file."
Name strFile & "txt" As strFile & "bak"
Set Sh = CreateObject("Wscript.Shell")
Sh.Run "sort " & strFile & "bak /O " & strFile & "txt", , True
Set Sh = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 


FYI,

Back in the days of Hollerith Card Sorters (IBM 80 Column Punch Cards), each sort was on ONE COLUMN. How could you sort, for instance, a ZIP Code of 5 digits?

You sort from the Lease Significant to the Most Significant Character.

Check it out!

Skip,
[sub]
[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue][/sub]
 
Hollerith Card Sorters? Hoooo boy, and I thought I was ancient. This shop was the last major mainframe operation in North America to use punch cards......ah the good old days. Except of course when the card sorter bombed and we had to sort 7 or 8 THOUSAND cards by hand....

Gerry
 


Gerry,

Ever have to punch in your own bootstrap codes to start the machine? VALUE/ADDRESS...

Skip,
[sub]
[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue][/sub]
 
Yes. Sigh.

I have on my wall a hard drive platter that is 16 inches across. It has grooves gouged out it when the head crashed. You may recall that was where the term "crashed" really came from. The noise it made was incredible.

Anyway, a new person here saw it, and wondered about it. I told him the story and he said, my God, that must be gigabytes and gigabytes...look at the SIZE of that thing. I literally could not make him believe that it was a 5 Mb platter, and that it once held our main database.

I gave him my report of eons ago, when we first tried to install TCP/IP...and could not get workstations to connect because we were 3K (3K!) short of RAM. Spent four days trying to get that darn 3K free.

He looked at me like I was mentioning chatting with Moses. Like...sure man...sure....3K? K?, you mean MEGAbytes, right? No sonny, I don't, and that platter on the wall? It really held HALF of just the .EXE part of Microsoft Word - never mind all the other files needed to make it run.

Not too many people truly remember what bootstrap actually means. Boot means "start", right? Wellllll, not exactly...

Bootstrap codes? Oh dear. I feel old. Wait a minute...I AM old. Sort of. Mind you, back then EVERYthing was cutting edge, and it was kind of fun. Sort of.

3K...for want of a nail.....

Gerry
 


I worked a project in 1982 on a Perkin-Elmer with 256K Memory. The system was to capture 16 channels of real-time data from an artilliary firing, so the disk had to be shipped. All the code for calibrating the channels, and controlling the firing sequence and space to capture of the data samples had to reside in 256K.

Lot of water over the dam since then!

Skip,
[sub]
[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue][/sub]
 
I started on an IBM 1620 with 1K hand wired board. I still have the board with all those little donuts!

 


How about a wire jumper board for programming.

And prior to that, installed the first analog to digital converter (an 8 ft x 4 ft x 3 ft cabinet) containing the a-d / d-a converter components for a shipboard missile radar, circa 1966.

Now it would fit in the palm of your hand, be faster and more precise.

Skip,
[sub]
[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue][/sub]
 
Yep a Univac 1004 printer with an 80x80 board with diode wires (Huge bunch of spaghetti)!

But I believe that Skip was around when the Red Sox won the other World Series!!
 


I wish! Been to Fenway many times, cica Yaz. In fact, was in the infield stands on sept 12, 1979, scorebook 'n' all for # 3000!

Skip,
[sub]
[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue][/sub]
 
Damn you guys are old!!

[wink]
Dave

"Probably the only Test Analyst on Tek-Tips"

Take a look at Forum1393 & sign up if you'd like
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top