Perl のような正規表現を処理できるssed
(super )に出会いました。sed
Debian ライクなシステムで利用できるはずですが、他のシステムについては不明です。
$ echo ' A-B becomes A\texthyphen B.
a-b becomes a\texthyphen b.
%-b becomes %\texthyphen b.
%-% is unchanged, because it is not near any letter.
1-2 is unchanged, because it is near numbers.
A-2 is unchanged, because it is near one number.' | \
> ssed -R 's/(?<=[A-Za-z])-(?![0-9])|(?<![0-9])-(?=[A-Za-z])/\\texthyphen /g'
与える
A\texthyphen B becomes A\texthyphen B.
a\texthyphen b becomes a\texthyphen b.
%\texthyphen b becomes %\texthyphen b.
%-% is unchanged, because it is not near any letter.
1-2 is unchanged, because it is near numbers.
A-2 is unchanged, because it is near one number.