PDA

View Full Version : sed question



GrouchyGaijin
January 15th, 2013, 07:05 PM
Hi Folks,

This probably seems basic to most everyone here, but I could use some advice.

I have a script that will download my Google calendar in ics format and convert it to remind format.

That is cool, but I'd like the script, that I run as a cron job, to add some strings to the beginning of the remind file that is generated by the script that converts the ics file to a remind file.

Specifically:

FSET _days(x) iif(x>1, x + " days", x==1, "1 day", "")
FSET _hrs(x) iif(x>1, x + " hours", x==1, "1 hour", "")
FSET _mins(x) iif(x>1, x + " minutes", x==1, "1 minute", "")
FSET _smush(x, y) iif(x != "" && y != "", x + " and " + y, x + y)
FSET _countdown(x) _smush(_smush(_days(x/1440), _hrs((x - 1440*(x/1440))/60)), _mins(x%60))

Then before the script is done I want it to add the following to the end of each of the lines that come below (or after) the five listed above.

I'd like the following added to each line:

b (in [_countdown(trigdatetime()-current())])

Basically, this should give me a running countdown until a reminder in remind is due. Below is the bash script I have so far. (Beware, it is ugly and not at all well written.)

#!/bin/bash
wget https://www.google.com/calendar/ical/url-to-my-calendar/basic.ics
cat /home/grouchygaijin/basic.ics | /home/grouchygaijin/scripts/ical2rem.pl > ~/.ical2rem
rm /home/john/*.ics
/home/grouchygaijin/scripts/rg


I figured out a way to make this work.



sed -e 's/$/ (in [_countdown(trigdatetime()-current())])/' -i ~/.ical2rem
cat ~/file ~/.ical2rem > temp-file
mv temp-file ~/.ical2rem