1

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.

  • I wanted to remove all line breaks from text file What is the max size of those .TXT file? is there a way to auto-remove the line break using/from command @echo %SomeStringHere%>>file.txt No. – Akina Aug 30 '18 at 5:16
  • There are 3 line breaks. Thanks a lot, but is there another way that can update the text file without a new line break? – user3754804 Aug 30 '18 at 5:20
  • Batch processing is not suitable for processing text files. For example, all leading/trailing spaces will be removed unconditionally... I'd recommend to use more suitable instrument - VBS for example. – Akina Aug 30 '18 at 5:43
  • I would use a Notepad++ macro to do this – spikey_richie Aug 30 '18 at 9:14
  • @Akina+ it's a large crock, but CMD can write a variable value (or other string) to a file without adding CRLF by SET/P ="%var%" >>file <NUL (or > to not append) – dave_thompson_085 Aug 31 '18 at 9:26
0

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)

| improve this answer | |
  • Or just awk -vORS=+ 1 -- but OP's data appears to already contain the + so just awk -vORS= 1 -- plus END{print "\n"} if desired (not clear if it is). – dave_thompson_085 Aug 31 '18 at 9:30
0

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 +
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.