I need to delete lines in a file between the specific pattern matched and the matched line.
In the below code, I want to delete the lines from object Host "kali" { to the next occurrence of } (not to the last occurrence of }). and also delete the empty spaces after deletion.
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" ]
}
This is my code
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
rm -rf deletionfile.txt
Error show while executing script:
sed: no input files
This is the expected output: ( when i give kali as a input to script. )
object Host "linux" {
import "windows"
address = "linux"
groups = ["linux"]
}
object Host "windows" {
import "linux"
address = "linux"
groups = ["windows" ]
}