% cat input.txt \ % | sed -r -e 's~^(.*) = \((.*), (.*)\)$~\L\1 to \L\2-\L\3.~' \ % | sed -r -e 's~^([RL]+)$~:- op(700, xfx, to).\ndirection("\L\1").~' > input.pl :- op(700, xfx, to). direction("llr"). aaa to bbb-bbb. bbb to aaa-zzz. zzz to zzz-zzz.