Maxxer
Maxxer

Reputation: 1097

awk: add a line if missing

I've an awk script which processes .ICS calendar files. I need to add the ATTENDEE line if it's missing.

I already have a script which parses all the events taking in considerations only the ones I need given a CHECKPARM criteria. I need to add the ATTENDEE if it's not present already.

/BEGIN:VEVENT/ { cache = 1; }

/CHECKPARM/ {
    if( index( $0, var ) )
        printf( "%s", cached_lines );
    else
        drop = 1;
    cached_lines = "";
    cache = 0;
}

# this doesn't work
#!~ /ATTENDEE/ {
#    printf ("ATTENDEE: %s", organizer);
#}

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

!drop { print; }

/END:VEVENT/ { drop = 0; }

Upvotes: 0

Views: 233

Answers (1)

Fredrik Pihl
Fredrik Pihl

Reputation: 45662

Try using a flag, if line is present, set it, if not, add line. Something like this:

/ATTENDEE/ {att = 1}

!att {
    printf ("ATTENDEE: %s\n", organizer)
}

Upvotes: 1

Related Questions