sed search line and replace only text in that line

Solution 1:

$ sed '/Z/s/x/0/g' <input_file>