I'm trying to delete comments from file but what's important I want to leave specific strings:
## Something
# START
# END
These has to stay with rest not commented lines and I want to remove rest with "d" - this is important. I don't want to use print negation or other tricks because this sed command also process another things later with additional "-e".
Here is sample file:
# START
group1: user1@domain.com, user2@domain.com, user3@domain.com
group2: user3@domain.com, user4@domain.com
# S
#STAR
# start
# star
# comment is here
## Owner1
group3: user1@domain.com, user3@domain.com
## Owner2
group4: user4@domain.com, user3@domain.com
group3: user2@domain.com, user3@domain.com
# END
group5: user4@domain.com
alias1: user6@domain.com
I tried to use command like:
sed -e '/^#[^#]/d' sample.file
Which remove each line starting with "#" and next character is NOT "#" so it leaves "##" lines but how to manage removing rest without loosing # START and # END lines?
I need to do this in same command without pipes, "!p" or "p" versions it has to be this "d" modified version. Tried things like:
sed -e '/^#[^#][^S][^T][^A][^R][^T]/d'
or
sed -e '/^#[^#]\([^S][^T][^A][^R][^T]\|[^E][^N][^D]\)/d'
but nothing is working the way I want. I'm not sure if this is possible this way.
Expected output:
# START
group1: user1@domain.com, user2@domain.com, user3@domain.com
group2: user3@domain.com, user4@domain.com
## Owner1
group3: user1@domain.com, user3@domain.com
## Owner2
group4: user4@domain.com, user3@domain.com
group3: user2@domain.com, user3@domain.com
# END
group5: user4@domain.com
alias1: user6@domain.com
Greetings & thanks for help :)