• Text file processing utilities

    Author
    Topic
    #452002

    I wonder whether anyone here is an expert on GSAR or SED?

    GSAR: I can’t get the @responsefile command to work, and the minimal documentation loses any mention of a “response file” between versions 1.20 and 1.21

    SED: I can’t see how to add control characters (specifically CR and LF).

    Let me describe the problem.

    I have a text file which contains records of the form
    [DoW, date, time] up to 40 characters of message text with a blank character at the end
    real sample:
    [Thu, 2008-06-12 13:37:53] – Log emailed [Thu, 2008-06-12 13:38:01] – Administrator logout – IP:192.168.11.2
    BUT these are in one long string, without a carriage return/line feed pair after each training blank and before the [ character.

    Effectively I wish to replace
    ” [Mon,” with “crlf[Mon,”
    ” [Tue,” with “crlf[Tue,”
    ” [Wed,” with “crlf[Wed,”
    … down to
    ” [Sun,” with “crlf[Sun,”
    where crlf represents the hex characters 0D0A, so that the text is split into lines starting each time with the [ character before the day-of-the-week abbreviation.

    If I could get the response file to work, I would use GSAR, otherwise I would need to make seven passes, each processing a specific day-of-the-week.
    I’ve looked at various SED tutorials, but can’t find how to do what I want.

    Any ideas? Thanks

    BATcher

    Plethora means a lot to me.

    Viewing 1 reply thread
    Author
    Replies
    • #1114540

      From your description, couldn’t you just do a global replace of ” [” with a “[“? Or am I missing something? And does it have to be SED or GSAR?

      Alan

      • #1114543

        Inadequate requirements definition – some records have a second [ in their text.

        No, it doesn’t have to be GSAR or SED (I don’t know any others), but is does have to be command-line!

        BATcher

        Plethora means a lot to me.

        • #1114669

          (Edited by jonWallace on 26-Jun-08 23:48. expanded it a bit…)

          Have you looked at awk http://www.vectorsite.net/tsawk.html%5B/url%5D ? I used this recently for a similar job at work. I’ll get more information at work tomorrow (today really, it’s late here…) and post back.

          John

          • #1114692

            Thanks, John – I’ll look into this – but I always thought that “AWK” was just a shortened form of “awkward”! (Much like the IBM mainframe data selection utility “EasyTrieve” was known by us as “DiffiTrieve”…)

            BATcher

            Plethora means a lot to me.

            • #1114712

              You could also follow up the leads from the WikipediA entry for AWK. It’s not nearly as awkward as it may appear at first glance. And it has a power and elegance that should also appeal to a BATch file afficianado grin

          • #1114709

            OK. Get ahold of awk95.exe. I’m lazy so I put everything in the same directory so I don’t have to worry about filepaths.
            Create a textfile (I called it new2.awk) that looks like

            {gsub(/[/,”n[“);print > “new3.txt”}

            I made a file with your specimen data repeated twice on one big line and changed the second set to [Fri…] and saved that as new1.txt.
            Then from a commandline (in the same directory — see above) I typed

            awk95 -f new2.awk new1.txt

            This calls new2.awk which reads new1.txt and parses it and pipes the output to a file called new3.txt with one record per line.

            Hope this is some help

    • #1115171

      I hate to sound nosey or pushy here, but did you find a solution to your problem?

      • #1115177

        Hello John

        As quite often happens, more pressing matters made me put this matter on the back burner.

        I spent about five minutes writing a BATch file to make seven passes of the same file using GSAR, once for each day-of-the week, rewriting it each time to the same filename. Spectacularly inefficient, but will do for the moment until I have time to learn AWK…

        Now if I could afford the originally-mainframe utility SELCOPY I could have done the command coding in about the same five minutes!

        BATcher

        Plethora means a lot to me.

        • #1115259

          [indent]


          As quite often happens, more pressing matters made me put this matter on the back burner.


          [/indent]

          Yeah, I know how that one goes! There are always more pressing matters. Still good to see you’ve found a solution.

        • #1115274

          Sometimes the “sledge hammer” is the most expedient, if not elegant solution! (Guilty of similar offences evilgrin)

          I’d be interested your opinion of AWK, once you’ve had time to have a proper play with it.

        • #1115347

          > As quite often happens, more pressing matters made me put this matter on the back burner.

          Haven’t you sorted out your ironing regimen yet!? grin

          Alan

    Viewing 1 reply thread
    Reply To: Text file processing utilities

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: