So, I have a file with various entries contained in { } parenthesis. Example:
{
"classname" "waypoint"
"targetname" "w1"
"target" "w2"
"origin" "672 -1432 32"
"target2" "w9"
}
{
"classname" "light"
"light" "500"
"scale" "4"
"origin" "672 -1440 232"
}
{
"classname" "NPC_Tavion"
"angle" "180"
"origin" "860 -1092 -8"
}
{
"classname" "info_player_start"
"angle" "360"
"origin" "312 -1080 216"
}
{
"classname" "light"
"light" "500"
"scale" "4"
"origin" "320 -1304 232"
}
I want to delete the whole content within { } alongside the { } itself if a word NPC_ is found. So the outcome I want is:
{
"classname" "waypoint"
"targetname" "w1"
"target" "w2"
"origin" "672 -1432 32"
"target2" "w9"
}
{
"classname" "light"
"light" "500"
"scale" "4"
"origin" "672 -1440 232"
}
{
"classname" "info_player_start"
"angle" "360"
"origin" "312 -1080 216"
}
{
"classname" "light"
"light" "500"
"scale" "4"
"origin" "320 -1304 232"
}
I've found a thing that could do it within AWK, but I can only use Windows tools and/or Python. I have come up with a thing like that (well, I just found another codepiece and modified it):
bad_words = ['NPC_']
with open('oldfile.txt') as oldfile, open('newfile.txt', 'w') as newfile:
for line in oldfile:
if not any(bad_word in line for bad_word in bad_words):
newfile.write(line)
However, I have no idea how to make it include the other content within { }. I have found this question: Remove text between () and [] and I figured out something like that could work:
ret = ''
skip1c = 0
skip2c = 0
for i in test_str:
if i == '{':
skip1c += 1
elif i == '}' and skip1c > 0:
skip1c -= 1
elif skip1c == 0 and skip2c == 0:
ret += i
return ret```
But I have no idea how to mix the two :(