我需要删除文件中匹配的特定模式和匹配的行之间的行。
在下面的代码中,我要删除对象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)