編集用に開きたくない ASCII ファイルで小さな処理が必要な場合、自分のコードで多くの Perl ワンライナー正規表現を使用していることに気付きました。
この Perl ワンライナー コマンドに相当する Tcl はありますか?
perl -i.bak -pe 's/old/new/gi' filename
この種の機能を提供するリチャード・スーチェンワースhttp://wiki.tcl.tk/906の owh スクリプトを見てください。ヨアヒム
以前、Perl のようなコマンド ライン オプションを提供する Tcl スクリプトを作成したことがあります。私自身はあまり使用したことがありませんでした.Tclインターセプトにコードを送信する作業の演習でした。興味があれば、コードはhttps://bitbucket.org/glenn_j/tcl-command-line-one-liners/srcにあります。
このスクリプトを使用して、インプレースのファイルに対してシェルパイプラインを実行しますが、に変更commands="$1"
することもできます。printf '%s' "$1" > sometemporaryfile
sh -c "$commands"
tclsh sometemporaryfile
#!/bin/sh -e
# =====================================================
# filter file(s) without having to use a temporary file
# =====================================================
# EXAMPLE - remove first line and b-tags:
# in-place 'tail -n +2 | sed "s/<[Bb]>//g"' *.html *.htm
# # check that the commands did what you intended
# rm *.html~ *.htm~
if [ $# -lt 1 ]; then
printf '%s\n' "$0: usage: in-place commands [file ...]" >&2
exit 1
fi
commands="$1"
shift
for file; do
cp -fp -- "$file" "$file~"
sh -c "$commands" < "$file~" > "$file"
done