TransWikia.com

How to remove all line breaks from text file using Batch

Super User Asked by user3754804 on November 29, 2021

I wanted to remove all line breaks from text file
Example:

FILE1 +
FILE2 +
FILE3 +

The output should be

FILE1 + FILE2 + FILE3 +

I can’t find answers on search engine that can solve my problem that’s why I am here to ask this question.

Also is there a way to auto-remove the line break using/from command @echo %SomeStringHere%>>file.txt, because that’s the reason I’m having this problem, it automatically insert a line break before the string to insert? Or is there a command that can only update the text file without new line break? Thank you.

2 Answers

I would suggest installing awk. To do this on a OSX

brew install awk

Once installed you can add the following line to your bash script:

awk '{printf "%s+",$0} END {print ""}'

Note: If you are using Windows I suggest GAWK (http://gnuwin32.sourceforge.net/packages/gawk.htm)

Answered by Brett on November 29, 2021

test.txt

FILE1 +
FILE2 +
FILE3 +

join.bat

@echo off
setlocal enabledelayedexpansion
set outstring=
for /f "delims=" %%A in (test.txt) do set outstring=!outstring!%%A
echo outstring=%outstring%

output

c:Batch>join.bat
outstring=FILE1 + FILE2 + FILE3 +

Answered by Michael Harvey on November 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP