[Solved] sed command succesfuly find and replace in file , bit erasing everything in the new file

user63898 Asks: sed command succesfuly find and replace in file , bit erasing everything in the new file
i have this xml text in file named test2.txt

Code:
<This is a line of text with a year=2020 month=12 in it
This line of text does not have a year or month in it
This year=2021 is the current year the current month=1
This is the year=2021 the month=2/>


<This is a line of text with a year=33020 month=12 in it
This line of text does not have a year or month in it
This year=33020 is the current year the current month=1
This is the year=33020 the month=2/>

im running this regexp on the file : i like to commnet the first paragraph but leaving the rest of the file as is

Code:
sed -i -En '/./{H;$!d} ; x ; s/<(This.*2020.*)/>/<!--1-->/p' test2.txt

but the result is that the sed command removing all the rest of the string in the file and putting the result of the regexp init so now the test2.txt looks like this :

Code:
<!--This is a line of text with a year=2020 month=12 in it
This line of text does not have a year or month in it
This year=2021 is the current year the current month=1
This is the year=2021 the month=2-->

how can i run the regexp but leave the other text in the file ?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.