【发布时间】:2018-08-21 18:47:30
【问题描述】:
我有 3 个文件。一个是食物和类别的列表:
food="rice"
product="cereal"
food="beans"
product="bean"
food="cake"
product="bakery"
food="lettuce"
product="leaves"
第二个是食物清单:
food="rice"
food="beans"
food="cake"
food="lettuce"
在第三个文件中,我有包含 /food 文件字符串的行(例如 /food="rice"),我需要将这些字符串替换为第一个文件中列出的相应产品。为了简化:在文件 3 上从文件 2 中找到字符串,并在文件 3 上用文件 1 的下一行替换。 我想也许是 grep 和 sed 的组合,但我不知道如何...... 第三个文件看起来像这样
>[food="rice"] [some other sutff] [calories=398]
Here is a recipe with rice
>[food="beans"] [some other sutff] [calories=250]
Here is a recipe with beans
>[food="cake"] [some other sutff] [calories=100]
Here is a recipe for cake
>[food="lettuce"] [some other sutff] [calories=02]
Why would you need a recipe for lettuce?
我需要它看起来像......
>[product="cereal"] [some other sutff] [calories=398]
Here is a recipe with rice
>[product="bean"] [some other sutff] [calories=250]
Here is a recipe with beans
>[product="bakery" [some other sutff] [calories=100]
Here is a recipe for cake
>[product="leaves"] [some other sutff] [calories=02]
Why would you need a recipe for lettuce?
【问题讨论】:
-
能否请您也发布第三个文件的示例以及预期的输出示例,然后让我们知道?
-
我刚刚更新了帖子
-
请避免"Give me the codez" 问题。而是显示您正在处理的脚本并说明问题所在。另见How much research effort is expected of Stack Overflow users?
-
@SilviaJusti,还是不清楚,请详细说明一下?
-
为什么你需要只包含食物的第二个文件?