【问题标题】:Append lines of text file with lines from another text file将文本文件的行与另一个文本文件中的行追加
【发布时间】:2014-11-22 11:48:34
【问题描述】:

我只能访问 windows 及其命令行。

我有两个包含很多行的文本文件,file1 和 file2。我想将 file1 中的行与 file2 中的相应行追加。

file1 中的每一行如下所示:

apple Orange

file2 中的每一行如下所示:

banana

我希望输出如下所示:

apple Orangebanana

有什么想法吗?最好通过win命令提示符?

【问题讨论】:

标签: windows command-line text-files


【解决方案1】:

这使用file1.txtfile2.txt 作为输入文件并将它们交错到result.txt

@echo off
setlocal DisableDelayedExpansion
(
< file2.txt (
   for /F "delims=" %%a in (file1.txt) do (
      set file2Line=
      set /P file2Line=
      set "file1Line=%%a"
      setlocal EnableDelayedExpansion   
      echo(!file1Line!!file2Line!
      endlocal
   )
)
)>"result.txt"

pause

【讨论】:

  • 完美!谢谢你
猜你喜欢
  • 2011-08-02
  • 1970-01-01
  • 2011-07-24
  • 2017-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多