Reputation: 123
I have text file with content like below, i want to delete the lines from specific position..
like from -displayName: "TIBCO_EMS_2"
to excludeTopics: []
I tried like below.
DP=TIBCO_EMS_2
sed "/- displayName: $DP/,/excludeTopics/d" config.yml
But still no luck, is there any right command to use instead of sed.
emsServers:
- displayName: "TIBCO_EMS_1"
host: "8988.auf.net"
port: 7443
protocol: "tcp"
user: "admin"
password: ""
encryptedPassword: "xzID9SbHsQTMkoRSVTGu4g=="
encryptionKey: "EncryptionKey"
showTemp: false
showSystem: false
excludeQueues: [sample1 sample2]
excludeTopics: []
- displayName: "TIBCO_EMS_2"
host: "8988.auf.net"
port: 7333
protocol: "tcp"
user: "admin"
password: ""
encryptedPassword: "d4FqX7O6bZCDs2corcd2eA=="
encryptionKey: "EncryptionKey"
showTemp: false
showSystem: false
excludeQueues: [sample1 sample2]
excludeTopics: []
Upvotes: 0
Views: 92
Reputation: 14949
You can try this awk
:
awk -vRS= '!/displayName: "TIBCO_EMS_2"/{print}' filename
Without changing original format,
awk -vRS= '!/displayName: "TIBCO_EMS_2"/{print}' ORS="\n\n" filename
If you want to pass value in variable,
DP='"TIBCO_EMS_2"'
awk -vVAR="$DP" -vRS= '{patt="displayName: "VAR} $0 !~ patt{print}' ORS="\n\n"
Upvotes: 1
Reputation: 2891
You missed the quotation marks.
DP=TIBCO_EMS_2 sed "/- displayName: \"$DP\"/,/excludeTopics/d" config.yml
Upvotes: 0