Exact Learning Dynamics of In-Context Learning in Linear Transformers and Its Application to Non-Linear Transformers