Results 1 to 12 of 12
  1. #1
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,421
    Thanks
    33
    Thanked 195 Times in 175 Posts

    Text file processing utilities

    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

    Time prevents everything happening all at once...

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text file processing utilities

    From your description, couldn't you just do a global replace of " [" with a "<crlf>["? Or am I missing something? And does it have to be SED or GSAR?

    Alan

  3. #3
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,421
    Thanks
    33
    Thanked 195 Times in 175 Posts

    Re: Text file processing utilities

    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

    Time prevents everything happening all at once...

  4. #4
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Dundee, Scotland
    Posts
    404
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text file processing utilities

    <P ID="edit" class=small>(Edited by jonWallace on 26-Jun-08 23:48. expanded it a bit...)</P>Have you looked at awk http://www.vectorsite.net/tsawk.html ? 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
    John (Unreconstructed Jacobite)

  5. #5
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,421
    Thanks
    33
    Thanked 195 Times in 175 Posts

    Re: Text file processing utilities

    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

    Time prevents everything happening all at once...

  6. #6
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Dundee, Scotland
    Posts
    404
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text file processing utilities

    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
    <div style="width: 100%; background-color: #FFFFFF;">{gsub(/[/,"n[");print > "new3.txt"}</div hiblock>
    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
    <div style="width: 100%; background-color: #FFFFFF;">awk95 -f new2.awk new1.txt</div hiblock>

    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
    John (Unreconstructed Jacobite)

  7. #7
    5 Star Lounger
    Join Date
    Dec 2002
    Location
    Perth, Western Australia, Australia
    Posts
    730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text file processing utilities

    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 <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    <font face="Comic Sans MS" color="blue">TimOz</font>
    <img src=/S/flags/Finland.gif border=0 alt=Finland width=30 height=18> <img src=/S/flags/Australia.gif border=0 alt=Australia width=30 height=18>

  8. #8
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Dundee, Scotland
    Posts
    404
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text file processing utilities

    I hate to sound nosey or pushy here, but did you find a solution to your problem?
    John (Unreconstructed Jacobite)

  9. #9
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,421
    Thanks
    33
    Thanked 195 Times in 175 Posts

    Re: Text file processing utilities

    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

    Time prevents everything happening all at once...

  10. #10
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Dundee, Scotland
    Posts
    404
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text file processing utilities

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

    Yeah, I know how that one goes! There are always more pressing matters. Still good to see you've found a solution.
    John (Unreconstructed Jacobite)

  11. #11
    5 Star Lounger
    Join Date
    Dec 2002
    Location
    Perth, Western Australia, Australia
    Posts
    730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text file processing utilities

    Sometimes the "sledge hammer" is the most expedient, if not elegant solution! (Guilty of similar offences <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>)

    I'd be interested your opinion of AWK, once you've had time to have a proper play with it.
    <font face="Comic Sans MS" color="blue">TimOz</font>
    <img src=/S/flags/Finland.gif border=0 alt=Finland width=30 height=18> <img src=/S/flags/Australia.gif border=0 alt=Australia width=30 height=18>

  12. #12
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Text file processing utilities

    > 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!? <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Alan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •