On Wed, Jan 29, 2003 at 07:41:31PM +0000, Angus Leeming wrote:
> Point 1. The .* RE operator is EXTREMELY greedy. Try and avoid it if at all 
> possible.

Indeed.

> Point 2. Sometimes 'cut' is a better tool than 'sed'. I repectfully submit 
> that this:
> 
>         input=`grep "Last-Translator" $pofile` && {
>               # Remove 'Last-Translator: ' from the front of the string
>                 input=`echo $input | sed 's/  */ /g' | cut -d ' ' -f 2-`
>               # The string now consists of "Jo Bloggs <jo@home>..."
>               # Use the < and > to extract the two parts.
>                 translator=`echo $input | cut -d '<' -f 1 | sed 's/ *$//'`
>                 email=`echo $input | cut -d '<' -f 2 | cut -d '>' -f 1`
>         }
> 
> is cheaper and more robust than this:
>       grep "Last-Translator" $x | 
>               sed -e 's/"Last-Translator: \(.*\)\( *\)<\(.*\)>\\n"/"translator" => 
>"\1", 
Concerning cheapness:

  y=${x%<*}
  translator=${j#* }
  y=${x#*<}
  email=${y%>*}

should beat that. But that's a bash-ism, isn't it?

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)

Reply via email to