awk:将2个csv文件合并为1个
文件1 MNTawk:将2个csv文件合并为1个,awk,merge,Awk,Merge,文件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
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
awk -F':' 'NR==FNR{a[NR]=$0;next}{print a[FNR]$2}' mnt ytd
但是我无法为我的文件获得正确的语法
我有一个每月的任务,给我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%
)
)
)
像这样:
awk 'FNR==NR{a[$1]=$2 FS $3;next}{ print $0, a[$1]}' file2 file1
awk -F':' 'NR==FNR{a[NR]=$0;next}{print a[FNR]$2}' mnt ytd
- 标题被忽略
- 假设两个文件具有相同的行数
{…}
将mnt中的同一行(从哈希表中提取)与ytd中的当前行连接起来。然后打印。