小编Gid*_*ong的帖子

在每个匹配行之间插入单词

我想知道如何在 while 循环中检查文件的结尾。我在这里做的是如果有一些词,例如“菠萝”、“苹果”、“洋葱”、“橙色”等,我想使用 grep 命令查找包含特定词的行并发表一些评论“窗户”。例如,如果我使用grep 'a' 'file',那么它会找到“菠萝”、“苹果”和“橙色”。然后,最后我想把它打印成“菠萝,窗户,苹果,窗户,橙子,窗户”,像这样。所以,我想在 while 或 for 循环中设置一些条件。任何帮助将不胜感激。

编辑:示例输入

apple
banana
pineapple
orange
mandu
ricecake
meat
juice
milk
onion
green onion
Run Code Online (Sandbox Code Playgroud)

使用 grep 命令时的预期输出 --> grep 'a' 'file name'

apple
window
banana
window
pineapple
window
orange
window
mandu
window
ricecake
window
meat
window
Run Code Online (Sandbox Code Playgroud)

linux shell bash

3
推荐指数
1
解决办法
268
查看次数

标签 统计

bash ×1

linux ×1

shell ×1