How to write the straight bar with subscript as I have attached in the picture?

You can use this:
\left. \frac{dY}{dx_p} \right|_{p=1}
This code renders the "fraction" dY/dx_p surrounded by two large "bracket" symbols. The left bracket symbol is actually no symbol at all, and the right bracket is a vertical line.
And by the way, I usually want the "d" to be straight up, so I would write (with some help from Torbjørn T.):
\left. \frac{\mathrm{d}Y}{\mathrm{d}x_p} \right|_{p=1}
\rm, it has been deprecated for 20 years. See Does it matter if I use\textitor\it,\bfseriesor\bf, etc. You want\mathrm{d}. – Torbjørn T. Sep 10 '13 at 08:34