小编moh*_*rid的帖子

使用sed删除两个匹配模式之间的所有行,包括匹配的行

我需要删除文件中匹配的特定模式和匹配的行之间的行。

在下面的代码中,我要删除对象Host“ kali” {中的行到下一次出现的}(而不是最后一次出现的})。并在删除后删除空白区域。

object Host "linux" {
import "windows"
address = "linux"
groups = ["linux"]
}


object Host "kali" {
import "linux"
address = "linux"
groups = [linux ]
}


object Host "windows" {
import "linux"
address = "linux"
groups = ["windows" ]
}
Run Code Online (Sandbox Code Playgroud)

这是我的代码

clear
echo -e  "Enter the host to delete in config file"
cat > deletionfile.txt
clear
while read host
do
loc=`grep -il 'object.*Host.*"$host"' /home/afrith/config-file/*.conf`
sed -i "/^object.*Host.*\"$host\".*{$/,/^}$/d" $loc
done < deletionfile.txt …
Run Code Online (Sandbox Code Playgroud)

shell awk sed data-manipulation

-1
推荐指数
1
解决办法
138
查看次数

标签 统计

awk ×1

data-manipulation ×1

sed ×1

shell ×1