Re: Sorting only certain data in file.
From: John L (jl_at_lammtarra.notthisbit.fslife.co.uk)
Date: 02/17/05
- Previous message: Roland Jacob: "Re: Giving a menu, but restricting shell access ?"
- In reply to: TB: "Sorting only certain data in file."
- Next in thread: Dave Gibson: "Re: Sorting only certain data in file."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 17 Feb 2005 08:25:29 -0000
"TB" <chessgame@gmail.com> wrote in message news:1108440872.921191.250790@z14g2000cwz.googlegroups.com...
> I have a text file that has a lot of data in it that I need to sort. I
> have an application that has a command similar to `who` that shows all
> the users that are logged into the app. Every hour I have a script
> that gets the hostname, date, and the users. Unfortunately the command
> doesn't sort the users how I would like. What i would like is to sort
> by the users so that I can see multiple logins. Or better yet, show
> only the duplicate logins (in full so that I can see how many times
> they are logged in).
>
> Below is an example of what I have. Basically I need everything
> between the ### and the ------------------------ sorted, while
> maintaining the other parts so I know what server, day, and hour the
> data is for. (in the real file there are hundreds of users).
>
> I've been scratching my head on and off all day trying to come up with
> some way of doing this. Anyone have any ideas.
>
You could write a simple finite state automaton.
You have two states: server data, which you just want printed; and
user data, which you want to sort (and perhaps filter) before printing.
You change states from "server" to "user" when you see "###" and
from "user" to "server" when you see a blank line.
In the "server" state, you just print the input.
In the "user" state, you store each line in an array. When you
leave this state, you sort/process the array and then print it.
In a scripting language like awk (news:comp.lang.awk) or perl
you could have the first prototype within five minutes, and
then spend some time experimenting with different sorts of
processing to see which shows you data most clearly.
It may be that the sorting is best done externally: experiment.
-- John.
- Previous message: Roland Jacob: "Re: Giving a menu, but restricting shell access ?"
- In reply to: TB: "Sorting only certain data in file."
- Next in thread: Dave Gibson: "Re: Sorting only certain data in file."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|