【发布时间】:2016-02-05 11:31:02
【问题描述】:
我有两个文件如下。第一个是sample.txt:
new haven co-op toronto on $1245
joe schmo co-op powell river bc $4444
第二个是locations.txt:
toronto
powell river
on
bc
我们想使用sed 生成一个标记的sample-new.txt,在每个之前和之后添加;。这样最终的字符串将如下所示:
new haven co-op ;toronto; ;on; $1245
joe schmo co-op ;powell river; ;bc; $4444
这可能使用 bash 吗?实际文件要长得多(每种情况下有数千行),但作为一次性工作,我们不太关心处理时间。
--- 编辑添加---
我原来的做法是这样的:
cat locations.txt | xargs -i sed 's/{}/;/' sample.txt
但它只对每个模式运行一次脚本,这与您在此处提出的方法相反。
【问题讨论】:
-
请附上您解决此问题的尝试in your question。只有看到您的代码,我们才能帮助您编写代码。
-
@ghoti 添加了我早期的可怕方法。谢谢!