I am new to scripting and trying to remove multiple spaces in a line and replace it with a single space.
input.txt
Hello world
Welcome to python
the output should be like
Hello world
Welcome to python
I followed the below command
with open ('input.txt', 'r') as i_f, open ('output.txt', 'w') as o_f:
for line in i_f:
o_f.write(re.sub('\s+',' ', line))
My output is something like
Hello world Welcome to python
I am trying to substitute multiple spaces with a single space of every line. I do not want to join the multiple lines into a single line. Can anyone please help me to delete multiple spaces and replace them with a single space by not joining the lines. Any help would be appreciated. Thanks in advance.