find lines in txt file grouped on date string and delete that group each day

Discussion in 'Perl Misc' started by joeyej, Apr 11, 2006.

  1. joeyej

    joeyej Guest

    Hi - I have a txt file I'd like lines removed from grouped on date. I
    want to run a daily task at midnight to read the dates.inc file, locate
    the [same] group dates at the top and delete them i.e read the file,
    find "May 15" or "May 15, 2006," and remove the lines containing that
    string stopping at "May 16,". The program would kick off at night to
    strip one date grouping per run.

    <option value="May 15, 2006, (Monday), 10am">May 15, 2006, (Monday),
    10am
    <option value="May 15, 2006, (Monday), 1pm">May 15, 2006, (Monday), 1pm
    <option value="May 16, 2006, (Tuesday), 9am">May 16, 2006, (Tuesday),
    9am
    <option value="May 16, 2006, (Tuesday), 11am">May 16, 2006, (Tuesday),
    11am
    <option value="May 16, 2006, (Tuesday), 1pm">May 16, 2006, (Tuesday),
    1pm
    <option value="May 17, 2006, (Wednesday), 9am">May 17, 2006,
    (Wednesday), 9am
    <option value="May 17, 2006, (Wednesday), 11am">May 17, 2006,
    (Wednesday), 11am
    <option value="May 17, 2006, (Wednesday), 1pm">May 17, 2006,
    (Wednesday), 1pm
    <option value="May 17, 2006, (Wednesday), 3pm">May 17, 2006,
    (Wednesday), 3pm

    Thanks,

    Joe
     
    joeyej, Apr 11, 2006
    #1
    1. Advertisements

  2. joeyej

    jl_post Guest


    Dear Joe,

    So you want to delete lines from (and including) the first mention
    of "May 15" to (but not including) the first mention of "May 16"?

    If I'm correct, you can easily do so with this one-liner:

    perl -ne "print unless /May 15/ .. /May 16/ and not /May 16/" file.txt

    This will remove any lines from file "file.txt" that are on or after
    "May 15" but not on or after "May 16" (unless a "May 15" line is
    encountered again).

    I hope this helps, Joe.

    -- Jean-Luc
     
    jl_post, Apr 11, 2006
    #2
    1. Advertisements

  3. joeyej

    jl_post Guest


    Sorry, I forgot the '-i' switch (for "in place" editing). What I
    meant to say was:

    perl -ni -e "print unless /May 15/ .. /May 16/ and not /May 16/"
    file.txt

    -- Jean-Luc
     
    jl_post, Apr 11, 2006
    #3
  4. joeyej

    joeyej Guest

    Hi Jean-Luc -

    Thanks but the idea is not to have specific date search criteria coded
    in since the file includes many date groupings. I was hoping for code
    that would read the date grouping at the beginning of the dates.inc
    file and delete only the lines containing that same string. This
    process would run each midnight until all date groups were [singly]
    removed.

    Joe
     
    joeyej, Apr 11, 2006
    #4
  5. joeyej

    joeyej Guest

    Thanks Jim -

    You are correct in your assumption that I'm dealing with only one file.
    I'll try your suggestion.

    Joe

     
    joeyej, Apr 12, 2006
    #5

  6. OK.

    What part of all of that are you stuck on?

    If you show us the code you have so far, we will help you fix it.
     
    Tad McClellan, Apr 12, 2006
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.