Operating System - HP-UX
1833802 Members
2269 Online
110063 Solutions
New Discussion

Sorting the pages by field in 11th line.

 
David Selvaraj
Occasional Contributor

Sorting the pages by field in 11th line.

I've a text file coming out of report which has ^L as page breaks.
I want to sort the pages by some positions(fields) in 11th line..
Please advice
8 REPLIES 8
Paula J Frazer-Campbell
Honored Contributor

Re: Sorting the pages by field in 11th line.

David

Can you attach an example of your file.


Paula
If you can spell SysAdmin then you is one - anon
David Selvaraj
Occasional Contributor

Re: Sorting the pages by field in 11th line.

Sorting fields are first 5 chars (till /) in line 11 and 12th lines first and last names.

For ex. employees and locations
Overall sort by locations
within the location by employee's last name.

Klaus Crusius
Trusted Contributor

Re: Sorting the pages by field in 11th line.


Try the attached script. AT least it will give you some idea.

Klaus
There is a live before death!
harry d brown jr
Honored Contributor

Re: Sorting the pages by field in 11th line.

You could use "csplit" and have it create a file for every page, then create an index of the filenames with the fields you want to sort on, then put them back together. Of course if the report has many pages.

Of course the simpler approach is to change the application that creates the report in the first place.

live free or die
harry
Live Free or Die
Klaus Crusius
Trusted Contributor

Re: Sorting the pages by field in 11th line.

assigning points to the replies is as easy as reading them, at least easier than providing the answers.
There is a live before death!
V. V. Ravi Kumar_1
Respected Contributor

Re: Sorting the pages by field in 11th line.

hi,
i could not understand what do u want.
iam refering to ur employees and location example.

to sort on a particular column and with in that column with perticular string u can use sort -k option.

ex: sort -k 7,7

see sort man page

regds
Never Say No
Rodney Hills
Honored Contributor

Re: Sorting the pages by field in 11th line.

If the text files is not too large, then you could write a perl routine to slurp each persons set of records. While the routine slurpped in an entry, scan for the persons name and location. Store the slurpped lines into an array and put the location of the array into a hashed array keyed by the values you wish to sort on.

Then use perl's sort function to process the hashed array and dump out each persons entry.

If the text file is too large, then you will have to have a secondary file where you take each line of the original file, prefix it with your sort information plus a line counter, then call that standard unix "sort" command to sort the data.

Example-
12345Jones0001xxxxx xxxxxxx
12345Jones0002 12345/xxx
12345Jones0003 Henry W Jones

Then the unix sort command would be something like-

sort -t\t +0-2 newfile

Their is another newer syntax to the sort command, and you could look it up in the "man" pages.

The line counters will make sure that the data stays in proper order for each person.

Many tasks within unix require some scripting/programming skills. Without writing the whole program, I hope I've given you enough ideas on how to proceede.

Good Luck

-- Rod Hills
There be dragons...
David Selvaraj
Occasional Contributor

Re: Sorting the pages by field in 11th line.

I'll start writing as a Perl Script.
thanks to you all.