Re: using regex substitution on BASH variables
On Mon, Jan 26, 2004 at 03:54:52PM -0500, David Z Maze wrote:
> Matt Price <matt.price@utoronto.ca> writes:
>
> > Now, if this information were stored in a file, it would be simple to
> > manipulate with regex's:
> >
> > sed 's/@/ -at- /' addressfile
> >
> > But I don't see an obvious way to get sed or awwk to take variable values
> > as input. I can do the following:
> >
> > FROM=`formail -x"From:" < "$msg"` ;
> > echo $FROM > tempfrom
> > FROM=$(sed 's/@/ -at- /' tempfrom)
> >
> > but this strikes me as awkward. Is there a better way?
>
> You can use sed and friends in a shell pipe. So a typical invocation
> would look something like
>
> FROM=`formail -x"From:" < "$msg" | sed -e' s/@/ -at- /g'`
>
> (Run formail, taking its input from the file named in $msg; then send
> its output through sed, and take the result of that and assign it to
> $FROM.)
wow, that's great, thdanks!
matt
>
Reply to: