It would really make my work easier if someone could help me with writing script in python or perl in which from given file it retreives all sentences like:
[LANG::...]
for ecxample:
[LANG::Sample text with digits 0123]
and writes it to the fileeach in single line.
Thanks very much for help
EDIT:
Thanks for help, and now something more advanced.
if it finds something like [:ANG:: ...] please write only ... without brackets ang LANG:: tag.
Thanks guys You are awesome :)
import re
with open('input.txt', 'w') as f:
text = f.read()
#text = 'Intro [LANG::First text 1] goes on [LANG::Second text 2] and finishes.'
with open('output.txt', 'w') as f:
for match in re.findall('\[LANG::.*?\]', text):
f.write(match+'\n')
outputs:
[LANG::First text 1]
[LANG::Second text 2]
Second part of the question: if it finds something like [:ANG:: ...] please write only ... without brackets and LANG:: tag.
Change the last part to:
with open('output.txt', 'w') as f:
for match in re.findall('\[.ANG::.*?\]', text):
if match.startswith('[:ANG'):
f.write(match[7:-1]+'\n')
else:
f.write(match+'\n')
Fix that substring part match[7:-1] to your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With