0

I'm trying to merge multiple text files into one single file. The problem with the command below is that it creates several whitespaces in the final merged file content and can't have any spaces. How can I fix the script to remove all the whitespaces from the file content?

@echo off
For %%I in (*.txt) do (
  type %%I >> MERGED.tmp
  Echo. >> MERGED.tmp
)
REN MERGED.tmp MERGED.txt
Exit

Here is how it looks with the white spaces

Merged list containing with white spaces

This is the desired result

Merged list with no spaces

2
  • Are you referring to space in the file name, or white space in the file content? If file content, then you need to be more specific as to exactly what you want removed. An example of original source followed by desired output would probably help.
    – dbenham
    Jan 16, 2014 at 21:03
  • The white space is in the file content. I have multiple text files containing a list of numbers and I trying to combine all these file into one single file. Ex text1.txt A00001L1 B00002L4 C00003L2 X00004L5 Z00005L3 The script Im using is adding a white space at the end of the last number when I merge it.
    – YOREL
    Jan 17, 2014 at 15:04

1 Answer 1

0

Don't use type, use copy *.txt merged.txt. You can use quotation marks for filenames with spaces.

1
  • The Copy *.txt creates a black arrow at the end and also put the first number of each list horizontally next to the last number of each list in the final merged.
    – YOREL
    Jan 17, 2014 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .