[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: using regex substitution on BASH variables



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.)

-- 
David Maze         dmaze@debian.org      http://people.debian.org/~dmaze/
"Theoretical politics is interesting.  Politicking should be illegal."
	-- Abra Mitchell



Reply to: