i'm working on the sed thing tbh with all the issues I'm having with python
C:\Games\Dwarf Fortress\github comparisons\BasedOnVanillaRaws\BasedOnVanillaRaws
\test_SafetoDeleteMe>py test.py < item_gloves.txt
Traceback (most recent call last):
File "test.py", line 3, in <module>
print(re.sub("]\s*([^[]*?)\s*[","]\n\\1\n[",sys.stdin.read()))
File "C:\Python34\lib\re.py", line 175, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "C:\Python34\lib\re.py", line 288, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Python34\lib\sre_compile.py", line 465, in compile
p = sre_parse.parse(p, flags)
File "C:\Python34\lib\sre_parse.py", line 746, in parse
p = _parse_sub(source, pattern, 0)
File "C:\Python34\lib\sre_parse.py", line 358, in _parse_sub
itemsappend(_parse(source, state))
File "C:\Python34\lib\sre_parse.py", line 484, in _parse
raise error("unexpected end of regular expression")
sre_constants.error: unexpected end of regular expression
C:\Games\Dwarf Fortress\github comparisons\BasedOnVanillaRaws\BasedOnVanillaRaws
\test_SafetoDeleteMe>
try2
C:\Games\Dwarf Fortress\github comparisons\BasedOnVanillaRaws\BasedOnVanillaRaws
\test_SafetoDeleteMe>python test.py <item_gloves.txt >test.txt
Traceback (most recent call last):
File "test.py", line 3, in <module>
print(re.sub("]\s*([^[]*?)\s*[","]\n\\1\n[",sys.stdin.read()))
File "C:\Python34\lib\re.py", line 175, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "C:\Python34\lib\re.py", line 288, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Python34\lib\sre_compile.py", line 465, in compile
p = sre_parse.parse(p, flags)
File "C:\Python34\lib\sre_parse.py", line 746, in parse
p = _parse_sub(source, pattern, 0)
File "C:\Python34\lib\sre_parse.py", line 358, in _parse_sub
itemsappend(_parse(source, state))
File "C:\Python34\lib\sre_parse.py", line 484, in _parse
raise error("unexpected end of regular expression")
sre_constants.error: unexpected end of regular expression
I don't know. i've spent too much time on this already. I could have just finished up my own manual parsing of tokens in c by now.
I have no idea how regular expressions work. There were some fancy suggestions to use readahead, and I think negative readahead (that were mentioned on stackexchange)
This matches any character followed by a [
but... I'm not sure how to use sed to replace *[ with *NewLine[
sed -e "s/[^[]*//"
Here's the sample file
item_gloves
[OBJECT:ITEM]
###test###[ITEM_GLOVES:ITEM_GLOVES_GAUNTLETS]###test###
[NAME:gauntlet:gauntlets]###test###
[ARMORLEVEL:2][UPSTEP:1]###test###
[SHAPED]
[LAYER:ARMOR]###test######test###
[COVERAGE:100]
###TEST
[LAYER_SIZE:20]
[LAYER_PERMIT:15]
[MATERIAL_SIZE:2]
[SCALED]
[BARRED]
[METAL]
[LEATHER]
[HARD]
desired output
item_gloves
[OBJECT:ITEM]
###test###
[ITEM_GLOVES:ITEM_GLOVES_GAUNTLETS]
###test###
[NAME:gauntlet:gauntlets]
###test###
[ARMORLEVEL:2]
[UPSTEP:1]
###test###
[SHAPED]
[LAYER:ARMOR]
###test######test###
[COVERAGE:100]
###TEST
[LAYER_SIZE:20]
[LAYER_PERMIT:15]
[MATERIAL_SIZE:2]
[SCALED]
[BARRED]
[METAL]
[LEATHER]
[HARD]
I suppose since I'm using a wildcard, I have to store a variable...
SED s/abc/xyz/g filename
That means substitute xyz with abc for the whole file.