-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconcat.py
More file actions
26 lines (19 loc) · 757 Bytes
/
concat.py
File metadata and controls
26 lines (19 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import re
input_file = 'nginx.yml'
with open(input_file, 'r') as f:
content = f.read()
# Define the regex pattern
# captures " file: " followed by anything until end of line
pattern = r"(^\s*)file:\s*(.*\.yml)"
# Define a function to generate the replacement
def replacement_func(match):
prefix = match.group(1) # The " file: " part (keeps indentation)
old_val = match.group(2) # The "html-cra.yml" part
content = ""
with open(old_val, 'r') as f:
for line in f:
content += f"{prefix} {line}"
return f"{prefix}source: |\n{prefix} {content.strip()}"
# Apply the substitution line by line (multiline flag)
new_content = re.sub(pattern, replacement_func, content, flags=re.MULTILINE)
print(new_content)