I butchered a shell script together, but my script kung-fu is 5 years old and all I've used for 5 years are for i loops. I hope that some perl guru can do in 5 minutes what takes me 5 weeks, so I am asking for help.
I have a simple script using "grep -A 2 'string' /path/to/file" but after importing my data into it (if's a FF plugin called ReminderFox), the rows are "re-ordered"
script now outputs: (source ics file is 'US Holidays')
But grep'ing with the same command on my backup file, I get this kind of output:
SUMMARY:Technical Support Specialist
UID:1281092384117-979283602
DTSTART:20100812T085900''
In simplest terms, my request is...
I'd like to have these fields from any ics file that has them:
SUMMARY:
DTSTART;VALUE=DATE:
DTEND;VALUE=DATE:
(and echo a newline)
and if possible convert DTSTART|DTEND data...
from it's current format of "+%Y%m%d" to "+%h %m %Y"
This is NOT homework.
Bash = GNU bash, version 4.0.38 | Awk = GNU Awk 3.1.7
Grep = GNU grep 2.6.3 | perl = 5.10.0
How to save it into a .pl file ?
Well, open up your favorite text editor, type in the Perl program, save and quit so that "cat -n basic.pl" spews something like the following:
$
$
$ cat -n basic.pl
1 #!/usr/bin/perl -w
2 # determine the current year first
3 my $year = (localtime)[5]+1900;
4 # set the "ics" file
5 my $file = "basic.ics";
6 # process the file now
7 open (F, $file) or die "Can't open $file: $!";
8 while (<F>) {
9 if (/SUMMARY/) {
10 print;
11 } elsif (/(DTSTART;VALUE=DATE:)($year)(\d\d)(\d\d)/) {
12 print "$1$3 $4 $2\n";
13 } elsif (/(DTEND;VALUE=DATE:)($year)(\d\d)(\d\d)/) {
14 print "$1$3 $4 $2\n\n"
15 }
16 }
17 close (F) or die "Can't close $file: $!";
$
$ perl basic.pl
SUMMARY:Washington's Birthday
DTSTART;VALUE=DATE:02 15 2010
DTEND;VALUE=DATE:02 16 2010
SUMMARY:Washington's Birthday
SUMMARY:Veterans Day
DTSTART;VALUE=DATE:11 11 2010
DTEND;VALUE=DATE:11 12 2010
...
... <output snipped for brevity>
...
SUMMARY:Christmas Eve
SUMMARY:Christmas Eve
DTSTART;VALUE=DATE:12 25 2010
DTEND;VALUE=DATE:12 26 2010
SUMMARY:Christmas
SUMMARY:Christmas
DTSTART;VALUE=DATE:04 01 2010
DTEND;VALUE=DATE:04 02 2010
SUMMARY:April Fool's Day
SUMMARY:April Fool's Day
$
$
The program takes into account the current year requirement as well.