2

I hope you're all doing well.

I have a simple command-line prompt that I use on Windows to concatenate all TXT files into one file named "merged."

copy *txt merged.txt

However, I've encountered an issue where, in the merged file, on the second row, two barcodes are placed next to each other on one line. Ideally, "11073-18216,28" should be on one line, and "11073-6185,12" should be on the next line. Does anyone know why this might be happening?

Attached below are 3 txt files for convenience. Thanks a lot

https://files.fm/u/6pzku5mst4

1

1 Answer 1

6

I have looked at your files, and this is entirely natural.

You're concatenating as-are files that have no line-endings, so the first line of the next file gets added to the last line of the previous text file.

To add a line-ending between files needs code similar to the following:

type A01.txt >merged.txt
echo. >>merged.txt
type A03.txt >> merged.txt
echo. >>merged.txt

The special command echo. will print an empty line, which is just a line ending, that gets concatenated to the last line of the last file.

This one-liner entered in the Command Prompt will do it for all .txt files. The result file is stored in the parent folder (or elsewhere if you wish) to avoid a loop:

 FOR %f IN (*.txt) DO type %f >> ..\merged.txt & echo. >> ..\merged.txt

You must log in to answer this question.

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