Ha a feladathoz választod az eszközt, akkor valami ilyesmi a megoldás:
#!/usr/bin/env bash
for i in *.tex ; do
sed -i 's/\\lnff\ \([[:alpha:]]\)\([[:alpha:]]*\)/\\letf{\1}{\2}/' "$i"
done
Ha ragaszkodsz a Pythonhoz:
#!/usr/bin/env python3
import os
import sys
import re
def find_tex(folder):
matches = []
for root, dirnames, filenames in os.walk(folder):
for filename in filenames:
if filename.endswith('.tex'):
matches.append(os.path.join(root, filename))
return matches
def main(argv):
if (len(argv) == 1):
print("Directory name?")
exit(1)
else:
folder = argv[1]
p = re.compile(r'^\\lnff (?P<head>\w)(?P<tail>[\w]*)')
files = find_tex(folder)
for filename in files:
with open(filename, 'r') as tex_file:
lines = []
for line in tex_file:
lines.append(line)
with open(filename, 'w') as tex_file:
for line in lines:
tex_file.write(p.sub(r'\\letf{\g<head>}{\g<tail>}', line))
if __name__ == '__main__':
main(sys.argv)
Bár hozzáteszem, hogy Pythonul nem nagyon tudok. Tehát nem kizárt, hogy ez a megoldás sok sebből vérzik.