Jul-01-2019, 06:54 AM
It seems to me that if you are looking for certain strings it will be easier without regex
I am not familiar with Python 2 syntax therefore I use Python 3 code:
In your code you use old-style open and 'with open(...'. What is the reason of such mix?
I am not familiar with Python 2 syntax therefore I use Python 3 code:
with open('cars.txt', 'r') as source: cars = ['[cars]\n'] trucks = ['[trucks]\n'] for row in source: if 'car' in row: cars.append(row) elif 'truck' in row: trucks.append(row) with open('cars_result.txt', 'w') as filtered: print(*cars, *trucks, file=filtered)cars_result.txt will look like:
Output:[cars]
car1
car2
[trucks]
truck1
truck12
truck13
Ansible is not my cup of tea but quick check of documentation revealed statements about support of Python 3. In your code you use old-style open and 'with open(...'. What is the reason of such mix?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.