Combinining多个文本文件合并成一个 [英] Combinining multiple text files into one

查看:158
本文介绍了Combinining多个文本文件合并成一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索高与低,似乎并不能找到我的问题的任何解决方案!我有多个文本文件,我想结合。

I have searched the internet high and low, and can't seem to find any solution for my problem! I have multiple text files that i would like to combine.

更容易表现出比的例子来解释究竟为什么我想要做的事。

it's easier to show examples than to explain exactly why i'm trying to do.

第一个文件看起来像这样

the first file looks like this

John
Paul
Mark
Sam
Herold

此文件作为主键

文件的其余部分包含这样的每个项目的数据。程序生成此数据到一个新的文件,每一个小时。

the rest of the files contain data for each item like this. A program generates this data into a new file each hour.

4
10
20
5
200

我最熟悉的Windows批处理文件,所以我试着写像这样

I'm most familiar with windows batch files, so I tried to write something like this

for /f "tokens=*" %%A in (file1.txt) do 
       (for /f "tokens=*" %%B in (file2.txt) do (echo %%A,%%B>>combined.txt))

不幸的是,每一个值写入到每个人。如果这样的工作,最终的结果会是这样。

unfortunately that writes every value to every person. If this were working, the end result would be like this

John,4,2,6,9,1,2,5,6,12,51,53,3,6,7,8,1,4,7,2,743,21,4,7,5
Paul,10,5,6,1,7,9,34,56,1,76,48,23,222,12,54,67,23,652,1,6,71,3,6,4

等。

我使用$ P $软件psents这种格式的数据,并且不能被改变。我愿意接受任何和所有的建议!

The software I am using presents the data in this format, and cannot be changed. I am open to any and all suggestions!

在此先感谢

推荐答案

您可以读取的若干个的输入通过标准的句柄的批处理程序文件。请记住,0为标准输入,1是标准输出和2是标准错误,但是这留下的手柄3〜9可用!下面的批处理文件做的文件合并的有两个文件的内容;当然,最多8个文件可以用这种方法进行组合。

You may read several input files in a Batch program via the standard handles. Remember that 0 is Stdin, 1 is Stdout and 2 is Stderr, but this leaves handles 3 to 9 available! The Batch file below do a file merge with the contents of two files; of course, up to 8 files can be combined with this method.

@echo off
setlocal EnableDelayedExpansion
Rem First file is read with FOR /F command
Rem Second file is read via standard handle 3
3< file2.txt (for /F "delims=" %%a in (file1.txt) do (
   Rem Read next line from file2.txt
   set /P line2=<&3
   Rem Echo lines of both files
   echo %%a,!line2!
))

进一步的细节在这里: HTTP://www.dostips。 COM /论坛/ viewtopic.php F = 3安培; T = 3126

这篇关于Combinining多个文本文件合并成一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆