Re: [Exim] Bug/Improvement in Readfile - Exim 4

Top Page
Delete this message
Reply to this message
Author: Philip Hazel
Date:  
To: Marc Perkel
CC: exim-users
Subject: Re: [Exim] Bug/Improvement in Readfile - Exim 4
On Mon, 16 Dec 2002, Marc Perkel wrote:

> Could you give me an example of how to do that with sg?


${sg{                                outer sg
    ${sg{                              inner sg                 ) operand
        ${readfile{/file}{|}}          operand for inner sg     )   for
        }                              end of operand           )  outer
        {\\|\$}                        match | at end           )    sg
        {}                             replace with nothing     )
     }                                 end of inner sg          )
    }                                end operand for outer sg
    {\\|\\|}                         match ||
    {|}                              replace with |
 }


I have not put in continuations characters. Also, you'll need to be
careful about the $ and \ in the regular expressions. I've put in the
escapes that are needed in an expansion string.

Hmm. Now that I think about it, you could probably do it all in one sg
call, which is probably more efficient:

${sg{
    ${readfile{/file}{|}}
    }
    {\\|(\\||\$)}
    {$1}
 }


The pattern now matches | followed either by another | or end of line.
The replacement just loses the first |. I have not tested either of
these. You should be able to test easily enough with "exim -be".

Regular expressions are your friend!

> Or - could you have some "smart" read file that would strip blank lines
> and comment lines as well?


I fear that is getting too special-purpose.

--
Philip Hazel            University of Cambridge Computing Service,
ph10@???      Cambridge, England. Phone: +44 1223 334714.