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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP!!!!!!!!!! :-) trying to sort a logfile

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Hi there, I have a quick question for ya!!!

I have only just started messing around with Perl and don't really know what im doing yet but I have created a couple of scripts that take data from a form and place it in a logfile.

The problem is I need to sort the output from this logfile by a "percent" colum (the last one in the below example) (ie 100% down to 0%)

Here's and example of what the log file looks like.

John Smith|john@smith.org|78.777
Joan Smith|joan@smith.org|65.987
phil Smith|phil@smith.org|68.776
tim Smith|tim@smith.org|100
dave Smith|dave@smith.org|98.13
carl Smith|carl@smith.org|13.8876

so on and so forth........

Is there anyway of reading the logfile and ordering the output so it has the highest percent first?

e.g.

name: email: percentage:
tim Smith tim@smith.org 100
dave Smith dave@smith.org 98.13
John Smith john@smith.org 78.777
phil Smith phil@smith.org 68.776
Joan Smith joan@smith.org 65.987
carl Smith carl@smith.org 13.8876


Any help you could give would be great!!!!

Many Thanks in advance....

mail me on wardy2001_booya@yahoo.co.uk
 
A single command from the Shell can perform the required task.

Try

sort -r -n +2 -t '|' logfile > newlogfile

should do the trick


HTH

regards
CM
 
Thats great, I'll give it a go.

Any chance of explaining exactly what the command does and what all the -r -n etc bits do......

Many Thanks.....
 
Can this run in a CGI script? if so please could you give me an example to look at.......

Many Thanks......
 
TO run it from a perl cgi script use the system command:
Code:
system("sort -r -n +2 -t '|' logfile > newlogfile");
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top