For Example: Need lines x, y, and z of Section 1 in File A to be copied to Section 1 in File B in between the brackets.
Need help where if given multiple files # of lines in File A section 1 will change, so always need in between brackets to copy over into in between brackets.
File A:
Section 1
{
x
y
z
}
Section 2
{
a
b
c
}
File B:
Section 1
{
}
Section 2
{
}
I am new so currently all I have been able to do is copy from one file into another file by:
with open(“File A”, “r”) as infile, open(“File B”,’w’) as outfile:
copy = False
for line in infile:
if line.strip() == “Section 1”:
copy = True
elif line.strip() == “}”:
copy = False
elif copy:
outfile.write(line)
But this copies into a new file:
{
x
y
z
So trying to figure out how to not copy the {, then also be able to paste into the new file in between {} depending on the section it is in.
Ashley Straub Treganza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.