How to merge files horizontally in Windows 7 comma

2019-09-09 04:03发布

问题:

I have three files in a directory
File 1:

a b
c d

File 2:

1 2
3 4

File 3:

e f
g h

I know that in windows command prompt, when I type "copy * new.txt", I get a file called new.txt which looks like the following.

a b
c d
1 2
3 4
e f
g h

In command prompt, how would I combine the files horizontally, so I get the following for my combined file?

a b 1 2 e f
c d 3 4 g h

回答1:

You can install some proper (Unix/Linux) tools from here and do it like this:

paste -d" " file1 file2 file3
a b 1 2 e f
c d 3 4 g h


回答2:

@echo off
setlocal EnableDelayedExpansion

3< File2.txt 4< File3.txt (
   for /F "delims=" %%a in (File1.txt) do (
      set "line1=%%a"
      set /P "line2=" <&3
      set /P "line3=" <&4
      echo !line1! !line2! !line3!
   )
)

Further details at this site.

  • You should use the batch-file tag for any "command prompt" related question.
  • You should upvote and select answers that had been useful to you, otherwise the people may refuse to answer your future questions.