How to merge files horizontally in Windows 7 command prompt?

孤人 提交于 2019-12-25 04:19:37

问题


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.


来源:https://stackoverflow.com/questions/24910000/how-to-merge-files-horizontally-in-windows-7-command-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!