Reputation: 63
I need to remove :
guide_change_names \
-design { lalala } \
{
}
from text file. Rules: there should be no word between {} lalala could be any word.
Text before:
guide_change_names \
-design { lalala } \
{
ha hah haha
}
guide_change_names \
-design { lalala } \
{
}
guide_change_names \
-design { lalala } \
{
lal lal lal
}
guide_change_names \
-design { lalala } \
{
}
Text After:
guide_change_names \
-design { lalala } \
{
ha hah haha
}
guide_change_names \
-design { lalala } \
{
lal lal lal
}
Upvotes: 3
Views: 74
Reputation: 11713
Try using GNU awk
awk 'BEGIN { RS="guide_change_names[^{]*{[^}]*}[^{]*{[ \n]*}[ \n]*" } 1' file
Here idea is to set Record Separator (RS) as the pattern to be removed.
Output:
guide_change_names \
-design { lalala } \
{
ha hah haha
}
guide_change_names \
-design { lalala } \
{
lal lal lal
}
Upvotes: 3
Reputation: 23394
You could use gawk. Set the record separator RS
to guide_change_names...}..}
and overwrite it to ""
if only spaces are contained between the second pair of curly braces
awk --re-interval -v RS='guide_change_names([^}]+[}]){2}\\n' \
'RT ~ /[{][[:space:]]+[}]\n$/{RT=""};{printf "%s%s", $0, RT}' file.txt
Upvotes: 3