procmail
[Top] [All Lists]

Re: Problem with lists expansion

1997-04-29 12:05:00
Era Eriksson was considering his previous suggestions to Pascal Dupuis:

|  >     sed -e 'y/\n/|/' -e 's/\|$//' 
| 
| I was unable to get any variant of this to work on two of the Unices I
| tried it on (Digital/OSF1, Sun) although they choked mainly on the
| newline in the y//. You are in a twisty maze of sed implementations,
| all different, so your mileage may vary. The following worked on
| Linux:
| 
|     sed -e 'y/
| /|/' -e '$s/|$//'
| 
| Given the problems with sed in general, I'd be partial towards using
| Perl instead;

sed's \n is not designed to match the trailing newline of the pattern space;
\n is advertised only to match *embedded* newlines.

All told, tr (without the useless cat, as Era has already pointed out)
is a much better way to handle this, and as Era and Eli have said, just
append some junk string after the trailing pipe.  Eli's concern about
a blank line in the input file is easily solved: use tr's -s option:

      CPDOM1=`tr -s '\12' '|' < $HOME/filters/cpdomains.1`

But if you really want to do it in sed, first, the file must fit into
sed's pattern space (usually 5000 characters); second, stated without
embedded newlines of its own so that it can be placed into a .procmailrc,
here goes:

 CPDOM1=`sed -e :a -e N -e '$ !ba' -e 's/\n\n*/|/g' $HOME/filters/cpdomains.1`

It won't add a trailing pipe at the end, and it will in defuse blank lines. 
Personally, I'd still go for tr and the junk string.

<Prev in Thread] Current Thread [Next in Thread>