Click here to Skip to main content
15,563,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text file. Example: inputfolder/abc.txt

Below is just an example - the actual file will have many lines which will vary everytime


Every line ends with '~' and I would like to merge all the lines into one

Desired output :


How can I merge all the lines into one line using windows command? ( I don't want to add any extra character)

Once all the lines are merged, the file should be moved to another folder Example: OutputFolder/abc.txt


What I have tried:

I want to execute this into windows command
Updated 18-Jun-21 1:54am
Dave Kreskowiak 17-Jun-21 20:08pm    
Define what you mean by "Windows command". Are we talking a .BAT or .CMD file? Powershell script, or what?

1 solution

Try this Powershell script:
$fileName = "file.txt"
# Get content of file
$content = Get-Content -Path $fileName -Raw -Encoding UTF8

# remove carriage return and newline characters
$newcontent = $content.Replace("`r","").Replace("`n","")

# display the changed text
Write-Host "Content: $newcontent"

# write the modified text to a new file
$newfilename = "newfile.txt"
Out-File -FilePath "$newfilename" -force -InputObject $newcontent
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900