  We prove a `motivic' analogue of the Weyl character formula, computing the
Euler characteristic of a line bundle on a generalized flag manifold $G/B$
multiplied either by a motivic Chern class of a Schubert cell, or a Segre
analogue of it. The result, given in terms of Demazure-Lusztig (D-L) operators,
recovers formulas found by Brubaker, Bump and Licata for the Iwahori-Whittaker
functions of the principal series representation of a $p$-adic group. In
particular, we obtain a new proof of the classical Casselman-Shalika formula
for the spherical Whittaker function. The proofs are based on localization in
equivariant K theory, and require a geometric interpretation of how the Hecke
dual (or inverse) of a D-L operator acts on the class of a point. We prove that
the Hecke dual operators give Grothendieck-Serre dual classes of the motivic
classes, a result which might be of independent interest. In an Appendix joint
with Dave Anderson we show that if the line bundle is trivial, we recover a
generalization of a classical formula by Kostant, Macdonald, Shapiro and
Steinberg for the Poincar{\'e} polynomial of $G/B$; the generalization we
consider is due to Aky{\i}ld{\i}z and Carrell and replaces $G/B$ by any smooth
Schubert variety.
