#====================================================================== #NAME #====================================================================== gen ( id 111 descr Test 1 txcd content ) #====================================================================== #NAME #====================================================================== gen ( id 112 descr Test 2 txcd content ) #====================================================================== #NAME #====================================================================== gen ( id 123 descr Test 3 txcd content ) I have this pattern, and have tried to find a way to delete a certain id using sed or awk. I pass the ID using a function parameter, $1. I've looked it up on stack but couldn't find a solution that worked for me.
sed -i "/gen \(/{:a;N;/\)/!ba};/$1/d" file
At a certain point when editing this sed command it did delete a line, but just the line where the ID itself was.
This is the one I've been working with, I've made small changes but nothing worked thus far. I'm supposed to delete the hashtags on top as well, but to begin with, I was mainly trying to delete the gen pattern.
\before a character) the(and)you changed their meaning into a group instead of a literal(or). Perhaps a functionf () { sed -i '/^gen (/{:a;N;/^)/M!ba;/'"$1"'/d' "${2:-file}"; }would meet your requirements (if you use bash)?