I found the answer in another post by user Qwerty.
Set the default value for textfield2 = textfield1 (this prevents the original data from being overwritten)
Then run the following rule on textfield2:
if textfield2 contacts @crlf
concat(substring-before(textfield2, @crlf), "XXXX", substring-after(textfield2, @crlf))
It ...