【发布时间】:2016-02-09 10:21:15
【问题描述】:
文件 1 MNT
title
from:,01.01.2016
to:,31.01.2016
days:,31
employees count:,169.00
counteddays:,206
counteddays KF:,141
counteddays KG:,65
percentage:,3.50%
percentage KF:,2.40%
percentage KG:,1.10%
results on:,08.02.2016
文件 2 年初至今
title
from:,01.01.2016
to:,08.02.2016
days:,39
employees count:,168.62
counteddays:,250
counteddays KF:,172
counteddays KG:,78
percentage:,3.38%
percentage KF:,2.33%
percentage KG:,1.06%
results on:,08.02.2016
我想得到什么:
title, month, ytd
from:,01.01.2016,01.01.2016
to:,31.01.2016,08.02.2016
days:,31,39
employees count:,169.00,168.62
counteddays:,206,250
counteddays KF:,141,172
counteddays KG:,65,78
percentage:,3.50%,3.38%
percentage KF:,2.40%,2.33%
percentage KG:,1.10%,1.06%
results on:,08.02.2016,08.02.2016
在另一个线程上我发现了这样的东西:
awk 'FNR==NR{a[$1]=$2 FS $3;next}{ print $0, a[$1]}' file2 file1
但我无法为我的文件找到正确的语法。
我有一个每月任务,它给了我 2 个上述格式的 csv 文件。 我的任务只是用基本的批处理工具或 awk 以简单的方式合并它们。
编辑:我尝试过的批处理方式,但不起作用:
for /f "tokens=1 delims=," %%a in ('type %MNT% ^| find ","') do (
for /f "tokens=2 delims=," %%b in ('type %MNT% ^| find "%%a"') do (
for /f "tokens=2 delims=," %%c in ('type %YTD% ^| find "%%a"') do (
echo %%a,%%b,%%c >> %RESULT%
)
)
)
【问题讨论】: