Skip to content

Commit f07e9ff

Browse files
committed
ioc alphabetical order parse file
1 parent 50d776d commit f07e9ff

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

scripts/sort_ioc.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# cmd: python sort_ioc.py [input.ioc] [formatted_output.ioc]*
3+
# formatted_output.ioc is optional, if not provided, input.ioc will be overwritten
4+
5+
6+
import sys
7+
8+
def sort_ioc_file(input_file, output_file=None):
9+
if output_file is None:
10+
output_file = input_file # overwrite original by default
11+
12+
with open(input_file, 'r', encoding='utf-8') as f:
13+
lines = f.readlines()
14+
15+
# Filter out empty lines and strip whitespace
16+
lines = [line.rstrip() for line in lines if line.strip()]
17+
18+
# Sort lines alphabetically by key (everything before '=')
19+
def key_func(line):
20+
if '=' in line:
21+
return line.split('=', 1)[0].strip()
22+
return line.strip()
23+
24+
sorted_lines = sorted(lines, key=key_func)
25+
26+
# Write back
27+
with open(output_file, 'w', encoding='utf-8') as f:
28+
for line in sorted_lines:
29+
f.write(line + '\n')
30+
31+
print(f"Sorted {input_file} -> {output_file}")
32+
33+
if __name__ == "__main__":
34+
if len(sys.argv) < 2:
35+
print("Usage: python sort_ioc.py <input_file> [output_file]")
36+
sys.exit(1)
37+
38+
input_file = sys.argv[1]
39+
output_file = sys.argv[2] if len(sys.argv) > 2 else None
40+
sort_ioc_file(input_file, output_file)

0 commit comments

Comments
 (0)