【发布时间】:2013-07-19 17:33:08
【问题描述】:
我有两个输入文件,一个只包含数字,例如
range.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
另一个文件有要求。例如
requirements.txt
2s 4m
1s 10m
这意味着 2 组每组 4 名成员和 1 组 10 名成员。
输出应该是这样的:
There is 1 apple;
There are 2 mangoes and 1 apple;
There are 3 mangoes and 1 apple;
There are 4 mangoes and 1 apple;
There is 5 apple;
There are 6 mangoes and 5 apple;
There are 7 mangoes and 5 apple;
There are 8 mangoes and 5 apple;
There is 9 apple;
There are 10 mangoes and 9 apple;
There are 11 mangoes and 9 apple;
There are 12 mangoes and 9 apple;
There are 13 mangoes and 9 apple;
There are 14 mangoes and 9 apple;
There are 15 mangoes and 9 apple;
There are 16 mangoes and 9 apple;
There are 17 mangoes and 9 apple;
There are 18 mangoes and 9 apple;
如何使用 awk 和 shell 脚本(甚至 perl)实现这一点?我们拥有的 awk 版本是 /usr/xpg4/bin/awk。我不熟悉数组,这就是为什么需要一些帮助。
谢谢!
PS:刚刚更新了将苹果“价值”附加到芒果“价值”的要求。
【问题讨论】:
-
很难理解这两个文件是如何组合在一起形成您的输出的。你能再澄清一下吗?
-
Florin,o/p 文件只使用 requirements.txt 和 range.txt 文件生成的值。