In space, the angle between two lines is measured through their directions, not their positions — two lines that never meet still have a well-defined angle between them (the angle you would see if you slid one across to meet the other).
So the angle between the lines is just the angle between their direction vectors. If the lines run along b1 and b2,
cosθ=∣b1∣∣b2∣∣b1⋅b2∣
Why the absolute value
A line has two opposite directions, so b and −b describe the same line. The modulus in the numerator picks the acute angle (0∘≤θ≤90∘), which is the convention for the angle between lines.
In Cartesian form
If the lines have direction ratios (a1,b1,c1) and (a2,b2,c2),