I need to concatenate some relatively large text files, and would prefer to do this via the command line. Unfortunately I only have Windows, and cannot install new software.
type file1.txt file2.txt > out.txt
allows me to almost get what I want, but I don't want the 1st line of file2.txt to be included in out.txt.
I have noticed that more
has the +n
option to specify a starting line, but I haven't managed to combine these to get the result I want. I'm aware that this may not be possible in Windows, and I can always edit out.txt by hand to get rid of the line, but is there a simple way of doing it from the command line?
Use the FOR command to echo a file line by line, and with the 'skip' option to miss a number of starting lines...
You could redirect the output of a batch file, containing something like...
Note the double % when a FOR variable is used within a batch file.
I know you said that you couldn't install any software, but I'm not sure how tight that restriction is. Anyway, I had the same issue (trying to concatenate two files with presumably the same headers) and I thought I'd provide an alternative answer for others who arrive at this page, since it worked just great for me.
After trying a whole bunch of commands in windows and being severely frustrated, and also trying all sorts of graphical editors that promised to be able to open large files, but then couldn't, I finally got back to my Linux roots and opened my Cygwin prompt. Two commands:
For
file1.csv
800MB andfile2.csv
400MB, those two commands took under 5 seconds on my machine. In a Cygwin prompt, no less. I thought Linux commands were supposed to be slow in Cygwin but that approach took far less effort and was way easier than any windows approach I could find.This takes
Test.txt
with headers and appendsTest1.txt
andTest2.txt
and writes results toTestresult.txt
file after stripping headers from second and third files respectively:I use this, and it works well for me:
TYPE \\Server\Share\Folder\*.csv >> C:\Folder\ConcatenatedFile.csv
Of course, before every run, you have to
DELETE C:\Folder\ConcatenatedFile.csv
The only issue is that if all files have headers, then it will be repeated in all files.
or you can use
copy
. Seecopy /?
for more.