Click here to Skip to main content
15,881,173 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

abcdefgh~
asdfghjkliuy~
qwertyuiopasdfgh~
..........


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

Desired output :

abcdefgh~asdfghjkliuy~qwertyuiopasdfgh~..................................


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

Thanks

What I have tried:

I want to execute this into windows command
Posted
Updated 18-Jun-21 0:54am
v2
Comments
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:
PowerShell
$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