Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
414 views
in Technique[技术] by (71.8m points)

regex - 如何将两个Windows ascii文本文件与cmd for循环组合?(How to combine two windows ascii text files with a cmd for loop?)

I've been trying to find a solution to this but can't find any .

(我一直在尝试找到解决方案,但找不到任何解决方案。)

Maybe someone has an idea on this.

(也许有人对此有想法。)

I have file1.txt which has one value per each line, and another file2.txt which has other values on each line.

(我有file1.txt ,每行一个值,另一个file2.txt ,每行有其他值。)

file1.txt

(file1.txt)

green
blue
red
[etc]

file2.txt

(file2.txt)

1
2
3
[etc]

I am trying to add all the values from file2.txt to the END of each of the values from file1.txt

(我正在尝试将file2.txt中的所有值添加到file1.txt中每个值的末尾)

The final output file will look like this

(最终的输出文件将如下所示)

output.txt

(output.txt)

green1
green2
green3
blue1
blue2
blue3
red1
red2
red3
[etc]

I've tried this in Excel to copy the values but it crashes.

(我已经尝试在Excel中复制值,但是它崩溃了。)

Ideally i'm looking for a way to do this on Windows : maybe a PowerShell command, or a regex expression somehow with a cmd prompt command?

(理想情况下,我正在寻找在Windows上执行此操作的方法:也许是PowerShell命令,还是以某种方式使用cmd提示命令的正则表达式?)

As these 2 files have lots of data, i don't see it working with Excel as it crashes constantly.

(由于这2个文件中包含大量数据,我认为它无法与Excel一起使用,因为它经常崩溃。)

Don't look at 1,2,3 as a pattern in file2.txt, they can be anything other than numbers;

(不要将1,2,3视为file2.txt中的模式,它们可以是数字以外的任何形式;)

so there is no pattern there;

(所以那里没有模式;)

it's just diff values compared to file1.txt

(与file1.txt相比,这只是差异值)

Would greatly appreciate any solution on this,

(非常感谢对此的任何解决方案,)

Thank you!

(谢谢!)

PS: in some cases I have 500k lines on file1.txt, and 1000 lines on file2.txt;

(PS:在某些情况下,我在file1.txt上有500k行,在file2.txt上有1000行;)

ideally I'd only use a cmd prompt or PowerShell command to work with the files..

(理想情况下,我只会使用cmd提示符或PowerShell命令来处理文件。)

  ask by Doug Lasore translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Windows 10 64-bit

(Windows 10 64位)

cmd:

(命令:)

cd.> file3.txt
for /f %a in (file1.txt) do for /f %b in (file2.txt) do echo %a%b>> file3.txt 
file3.txt 

script:

(脚本:)

cd.> file3.txt
for /f %%a in (file1.txt) do for /f %%b in (file2.txt) do echo %%a%%b>> file3.txt
file3.txt 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...