Your given integral is closely related to the Mellin transform and can be evaluated by using Ramanujan's Master Theorem.
Ramanujan's Master Theorem
Let $f(x)$ be an analytic function with a MacLaurin Expansion of the form
$$f(x)=\sum_{k=0}^{\infty}\frac{\phi(k)}{k!}(-x)^k$$then the Mellin Transform of this function is given by
$$\int_0^{\infty}x^{s-1}f(x)dx=\Gamma(s)\phi(-s)$$
Therefore expand the cosine function as Taylor series expansion to get
$$\begin{align}
\mathfrak{I}=\int_0^{\infty}\cos(x)x^{-p}dx&=\int_0^{\infty}x^{-p}\sum_{n=0}^{\infty}(-1)^n\frac{x^{2n}}{(2n)!}dx
\end{align}$$
In order to bring the above integral in the wanted form for the usage of Ramanujan's Master Theorem apply the substitution $x^2=u$. So we further get
$$\begin{align}
\mathfrak{I}=\int_0^{\infty}x^{-p}\sum_{n=0}^{\infty}(-1)^n\frac{x^{2n}}{(2n)!}dx&=\int_0^{\infty}x^{-p}\sum_{n=0}^{\infty}\frac{1}{(2n)!}(-x^2)^ndx\\
&=\int_0^{\infty}u^{-p/2}\sum_{n=0}^{\infty}\frac{1}{(2n)!}(-u)^n\frac{du}{2\sqrt{u}}\\
&=\frac12\int_0^{\infty}u^{-(p+1)/2}\sum_{n=0}^{\infty}\frac{1}{(2n)!}(-u)^ndu\\
&=\frac12\int_0^{\infty}u^{-(p+1)/2}\sum_{n=0}^{\infty}\frac{n!/(2n)!}{n!}(-u)^ndu
\end{align}$$
By using the relation $\Gamma(n)=(n-1)!$ which is valid for all $n\in\mathbb N$ we can consider the last integral as an application of Ramanujan's Master Theorem with $s=-\frac{p-1}2$ and $\phi(n)=\frac{\Gamma(n+1)}{\Gamma(2n+1)}$. By finally using the Theorem we obtain
$$\begin{align}
\mathfrak{I}=\frac12\int_0^{\infty}u^{-(p+1)/2}\sum_{n=0}^{\infty}\frac{n!/(2n)!}{n!}(-u)^ndu&=\frac12\Gamma\left(-\frac{p-1}2\right)\frac{\Gamma\left(\frac{p-1}2+1\right)}{\Gamma\left(2\left(\frac{p-1}2\right)+1\right)}\\
&=\frac1{2\Gamma(p)}\Gamma\left(1+\frac{p-1}2\right)\Gamma\left(-\frac{p-1}2\right)
\end{align}$$
Now by applying Euler's Reflection Formula with $z=1+\frac{p-1}2$ we moreover get
$$\begin{align}
\mathfrak{I}=\frac1{2\Gamma(p)}\Gamma\left(1+\frac{p-1}2\right)\Gamma\left(-\frac{p-1}2\right)&=\frac1{2\Gamma(p)}\frac{\pi}{\sin\left(\pi\left(1+\frac{p-1}2\right)\right)}\\
&=\frac1{2\Gamma(p)}\frac{\pi}{\sin\left(\frac{p\pi}2+\frac{\pi}2\right)}\\
&=\frac1{2\Gamma(p)}\frac{\pi}{\cos\left(\frac{p\pi}2\right)}
\end{align}$$
where within the last step the fundamental relation $\sin\left(x+\frac{\pi}2\right)=\cos(x)$ was used. Thus for the original integral $\mathfrak{I}$ we get
$$\mathfrak{I}=\int_0^{\infty}\cos(x)x^{-p}dx=\frac{\pi}{2\Gamma(p)\cos\left(p\frac{\pi}2\right)}$$