(解决)并排使用批处理文件合并几个csv文件侧 [英] (SOLVED) Merge several csv file side by side using batch file

查看:318
本文介绍了(解决)并排使用批处理文件合并几个csv文件侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找两个合并几个CSV文件合并成一个。不过,我需要他们合并,以使列并排不会在继续。
我的文件有每次两列,我会通过提取每个文件,复制到另外一个第2列,所以我将与x列的文件(第二个)有一个CSV文件。

例如。

文件1

  A B
1 2
1 2
1 2

文件2

  A C
1 3
1 3
1 3

FILEX

 一λ
1个
1个
1个

结果

  B C点¯x
2 3×
2 3×
2 3×

我发现这一点:<一href=\"http://stackoverflow.com/questions/22072181/merge-csv-file-side-by-side-using-batch-file\">Merge通过使用批处理文件侧csv文件一边

但它只是对两个文件,​​并没有任何提取

感谢。


解决方案

@ECHO OFF
SETLOCAL enabledelayedexpansion
::除去起始$变量
FOR / Fdelims ==%% a。在('设置$ 2 ^&GT;讷')DO SET一%% =
SET / $一个计数= 0
FOR %%一个IN(q28850167 * .TXT)DO(
 FOR / F令牌= 1,2 * delims =%% b在('FINDSTR / N / R^%%一个')DO(
  SET $ %% B =!$ %% b! %%ð
  IF!$算! LSS %% b设置/ A $计数= %% b
 )


FOR / L %%一个IN(1,1,%$计数%)DO ECHO($ %%一:〜!1!
)&GT; newfile.txt
GOTO:EOF

我用命名的文件 q28850167 * .TXT 包含您的数据,我的测试。结果
生产newfile.txt

清除所有变量开始 $

对于每个文件通过各线路匹配的面具,过程 FINDSTR / N 适用号:来启动的每一行。使用选择第一个和第三个+列:和<大骨节病>空间作为分隔符,并追加到变量 $行号跟踪的最高行号的 $计数

然后只需从存储的数据复制每一行。

I was looking two merge several csv files into one. However I need them merging so that the columns are side by side not continuing on. My files have two columns each time and I would have one csv files by extracting the 2nd column on each files and copying into another one so I will have a file with x columns (the second one).

e.g.

File1

A B
1 2
1 2
1 2

File2

A C
1 3
1 3
1 3

Filex

A X
1 x
1 x
1 x

Result

B C X
2 3 x
2 3 x
2 3 x

I found this : Merge csv file side by side using batch file

but it's just for two files and it doesn't extract anything.

Thanks.

解决方案

@ECHO OFF
SETLOCAL enabledelayedexpansion
:: remove variables starting $
FOR  /F "delims==" %%a In ('set $ 2^>Nul') DO SET "%%a="
SET /a $count=0
FOR %%a IN (q28850167*.txt) DO (
 FOR  /f "tokens=1,2*delims=: " %%b IN ('findstr /n /r "^" "%%a"') DO (
  SET $%%b=!$%%b! %%d
  IF !$count! LSS %%b SET /a $count=%%b
 )
)
(
FOR /L %%a IN (1,1,%$count%) DO ECHO(!$%%a:~1!
)>newfile.txt


GOTO :EOF

I used files named q28850167*.txt containing your data for my testing.
Produces newfile.txt

Clear all variables starting $

For each file matching the mask, process each line through findstr/n to apply number : to the start of each line. Select the first and third+ columns using : and Space as separators and append to variable $linenumber Keep track of the highest line number in $count.

Then simply reproduce each line from the stored data.

这篇关于(解决)并排使用批处理文件合并几个csv文件侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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