Re: Basic scripting

Damian Gerow <[email protected]>
Newsgroups gmane.user-groups.linux.ottawa.general
Message-ID <[email protected]>
chris h wrote:
: On Sunday 09 November 2008 23:07:55 Ross Jordan wrote:
: > If you could set up a procmail recipee, it could move mail to a
: > specified folder based on regex patterns.
: 
: No that would not work. What I need to do is extract the lat and lon data from 
: preformatted emails (where the data is in the body of the mail) and pipe the 
: data to a specified file.

... Which can very easily be done in procmail, *if* procmail is an option.
(This is the highly recommended way to go.)

I don't know if kmail even provides a scripting interface, but something
along the lines of this should do the trick:

> ESN:0-7361228A <------- this is the user code                                                                                                                                    
> Latitude:40.1058  <--- need only the data                                                                                                                                        
> Longitude:-74.0526 < -- same as above                                                                                                                                            
>                                                                                                                                                                                  
> way.txt format                                                                                                                                                                   
> ---------------------------------                                                                                                                                                
> svAdena                 40.097750  -74.064962 waypoint 0 0 0 0                                                                                                                   
> (name of waypoint)    (lat)           (lon)           (coord description)                                                                                                        

-----
#!/bin/sh

# There's a better way to do this.  It's called 'awk'.
LATITUDE=$(egrep '^Latitude:' ${MESSAGE} | sed 's/^.*://')
LONGITUDE=$(egrep '^Longitude:' ${MESSAGES} | sed 's/^.*://')

echo "svAdena	${LATITUDE}	${LONGITUDE}	waypoint 0 0 0 0" >> way.txt
-----

Unfortunately, there are a few things wrong with this:

0) It assumes the e-mail is a file called ${MESSAGES} on disk.
1) Does the name of the waypoint stay the same?
2) Does the co-ordination description ever change?
3) It's awfully inefficient; you should be able to compress the 'egrep' and
   'sed' into one line by using 'awk', but I don't know 'awk' well enough
   to pull out substrings (either by regex search-and-replace or regex
   groupings).
-- 
OCLUG general discussion list
[email protected]
http://oclug.on.ca/mailman/listinfo/oclug
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.