I have this file:
root@DESKTOP-PDVDCNC:/var/tmp# cat test.txt
monitoring:
email: ''
enabled: true
full_name: Kibana Application server
metadata: {}
roles: [ReadAllIndices]
username: monitoring
nagios:
email: null
enabled: true
full_name: Nagios Monitoring
metadata: {}
roles: [read_only]
username: nagios
monitor_stream_user:
email: null
enabled: true
full_name: null
metadata: {_reserved: true}
roles: [monitor_stream_collector, monitor_stream_agent]
username: monitor_stream_user
H4410603:
email: null
enabled: true
full_name: "John Doe"
metadata: {}
roles: [group1, group2, app_food, group3, group4, group5, application_memory]
username: H4410607
Q6655060:
email: jules_sayzan@carrefour.com
enabled: true
full_name: "Jules"
metadata: {}
roles: [group1, group2, app_food, group3, group5, application_memory]
username: Q6655060
A1090501:
email: ''
enabled: true
full_name: "Ruth Beneth"
metadata: {}
roles: [application_memory]
username: A1090507
and I want to delete 1 line before and after a matched line, and the matched line itself.
The matched line is : every line that contains: "group3" string.
I have try this with no sucess:
root@DESKTOP-PDVDCNC:/var/tmp# cat test.txt |sed -zE 's/([^\n]*\n){1}([^\n]*group3[^\n]*)(\n[^\n]*){1}/\2/g'