Re: Sorting only certain data in file.

From: John L (jl_at_lammtarra.notthisbit.fslife.co.uk)
Date: 02/17/05

  • Next message: liljencrantz_at_gmail.com: "Re: Announcing the friendly interactive shell"
    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.
    

  • Next message: liljencrantz_at_gmail.com: "Re: Announcing the friendly interactive shell"

    Relevant Pages

    • Re: Sort files by filename
      ... With apologies to the 2 Les', the situation isn't like that and I ... is running on a server that simply relays the data to all our ... but this is a production server that feeds 13MB/hr for each ... So I need to sort the files and check for missing ...
      (Fedora)
    • Re: OE6 says no new messages, but there ARE
      ... Then retry the View, Sort by. ... The server name is on the servers tab in the box labelled: ... It's like they download into a ... >> Troubleshooting Logging for Mail and verify that you see RETR requests. ...
      (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
    • NAS appliance or home server
      ... I've been meaning, for some time, to provide some sort of storage ... server for the motley collection of computers -- some Windows and some ... linux based -- that lurk around here. ... I'm torn between opting for an easy off-the-shelf NAS solution that may ...
      (uk.comp.os.linux)
    • Re: "Depreciated" Parameters In SPFILE
      ... however, in case you switch to shared server mode (or, remembering ... and Oracle is able to adjust the value of the parameter ... SORT_AREA_SIZE to 20MB, resulting in the elimination of the sort to ... dedicated server environment. ...
      (comp.databases.oracle.server)
    • Re: [Full-disclosure] phishing sites examples "source code"
      ... On 2/19/07, Juergen Fiedler wrote: ... code for the form action because it is done in some sort of server ... side scripting that can't readily be ... Can't readily be viewed BUT that part is sort of not-the-problem. ...
      (Full-Disclosure)