I'm trying to handle a file, and I need to remove extraneous information in the file; notably, I'm trying to remove brackets [] including text inside and between bracket [] [] blocks, Saying that everything between these blocks including them itself but print everything outside it.
Below is my text File with data sample:
$ cat smb
Hi this is my config file.
Please dont delete it
[homes]
browseable = No
comment = Your Home
create mode = 0640
csc policy = disable
directory mask = 0750
public = No
writeable = Yes
[proj]
browseable = Yes
comment = Project directories
csc policy = disable
path = /proj
public = No
writeable = Yes
[]
This last second line.
End of the line.
Desired Output:
Hi this is my config file.
Please dont delete it
This last second line.
End of the line.
What i have tried based on my understanding and re-search:
$ cat test.py
with open("smb", "r") as file:
for line in file:
start = line.find( '[' )
end = line.find( ']' )
if start != -1 and end != -1:
result = line[start+1:end]
print(result)
Output:
$ ./test.py
homes
proj