Perl - 按通用维度连接文件中指标的脚本

发布于 2024-11-25 12:52:05 字数 262 浏览 6 评论 0原文

我想根据共同维度将 3 个文件中的指标连接到 1 个文件中。

例如:

File 1:
A B C 10 20
A D C 30 40
File 2:
A B C 100 200
A D C 300 400
File 3:
A B C 1000
A D C 3000
Output File:
A B C 10 20 100 200 1000
A D C 30 40 300 400 3000

I want to concatenate the metrics from 3 files into 1 files based on common dimensions.

Eg:

File 1:
A B C 10 20
A D C 30 40
File 2:
A B C 100 200
A D C 300 400
File 3:
A B C 1000
A D C 3000
Output File:
A B C 10 20 100 200 1000
A D C 30 40 300 400 3000

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

将军与妓 2024-12-02 12:52:05

我将创建一个散列,其中每个键都是文件输入中的前 3 个字段,并迭代每个文件,将值推送到一个数组中,该数组就是散列的值。
请告诉我您是否想查看实际代码。

I would create a hash, where every key is first 3 fields from the file input, and iterate through every file pushing the values into an array which is the value of the hash.
Please let me know whether you would like to see actual code.

爱你不解释 2024-12-02 12:52:05

你真的不需要 perl 来做到这一点。这是一个有效的 2 行 shell 脚本:

join file1 file2 | sed -e 's/\([0-9]\) [A-Z] [A-Z] /\1 /g' > file4
join file3 file4 | sed -e 's/\([0-9]\) [A-Z] [A-Z] /\1 /g' > file5

file5 有你的输出数据

You really don't need perl for this. Here's a 2 line shell script that works:

join file1 file2 | sed -e 's/\([0-9]\) [A-Z] [A-Z] /\1 /g' > file4
join file3 file4 | sed -e 's/\([0-9]\) [A-Z] [A-Z] /\1 /g' > file5

file5 has your output data

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文