Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

awk parsing of ICS file

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 08-23-2011
mmtung mmtung is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 23 August 2011, 8:24 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
awk parsing of ICS file

Hi, I am searching for a fast awk hack to eliminate from an ICS file events which have been modified at a certain time.

The structure for parsing is the following:

BEGIN:VEVENT
....
LAST-MODIFIED:...some date...
...
END:VEVENT

If the date matches for example LAST-MODIFIED:20110823 the entire VEVENT (between begin and end) block should not be echoed to standard output; all other blocks should be echoed without change.

Many thanks for any help!
Best, Mike
Sponsored Links
    #2  
Old Unix and Linux 08-23-2011
agama agama is offline Forum Advisor  
Always Learning
 
Join Date: Jul 2010
Last Activity: 7 April 2014, 3:02 PM EDT
Location: earth>US>UTC-5
Posts: 1,466
Thanks: 110
Thanked 511 Times in 490 Posts
Have a go with this:


Code:
#!/usr/bin/env ksh

awk -v date=${1:-nodate} '
    /BEGIN:VEVENT/ { cache = 1; }

    /LAST-MODIFIED:/ {
        if( index( $0, date ) )
            drop = 1;
        else
            printf( "%s", cached_lines );
        cached_lines = "";
        cache = 0;
    }

    cache  {
        cached_lines = cached_lines $0 "\n";
        next;
    };

    !drop { print; }

    /END:VEVENT/ { drop = 0; }
'


Last edited by agama; 08-23-2011 at 07:45 PM.. Reason: typo
The Following User Says Thank You to agama For This Useful Post:
superpointer (01-10-2014)
Sponsored Links
    #3  
Old Unix and Linux 08-23-2011
mmtung mmtung is offline
Registered User
 
Join Date: Aug 2011
Last Activity: 23 August 2011, 8:24 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Many thanks for your speedy help. This worked just perfectly!
Cheers, Mike
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
parsing data from a big file using keys from another smaller file Lucky Ali Shell Programming and Scripting 10 04-06-2011 07:46 PM
Parsing of file for Report Generation (String parsing and splitting) umar.shaikh Shell Programming and Scripting 8 03-02-2009 12:38 AM
Parsing file, yaml file? Extracting specific sections Rhije Shell Programming and Scripting 3 01-22-2009 05:36 PM
Script for parsing details in a log file to a seperate file pingnagan UNIX for Dummies Questions & Answers 2 11-13-2008 11:21 AM
Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names nikosey Shell Programming and Scripting 6 07-30-2008 09:46 PM



All times are GMT -4. The time now is 06:33 AM.