5

編集用に開きたくない ASCII ファイルで小さな処理が必要な場合、自分のコードで多くの Perl ワンライナー正規表現を使用していることに気付きました。

この Perl ワンライナー コマンドに相当する Tcl はありますか?

perl -i.bak -pe 's/old/new/gi' filename
4

3 に答える 3

1

この種の機能を提供するリチャード・スーチェンワースhttp://wiki.tcl.tk/906の owh スクリプトを見てください。ヨアヒム

于 2012-11-14T14:51:08.787 に答える
1

以前、Perl のようなコマンド ライン オプションを提供する Tcl スクリプトを作成したことがあります。私自身はあまり使用したことがありませんでした.Tclインターセプトにコードを送信する作業の演習でした。興味があれば、コードはhttps://bitbucket.org/glenn_j/tcl-command-line-one-liners/srcにあります。

于 2012-11-14T16:59:36.960 に答える
0

このスクリプトを使用して、インプレースのファイルに対してシェルパイプラインを実行しますが、に変更commands="$1"することもできます。printf '%s' "$1" > sometemporaryfilesh -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
于 2012-11-15T03:03:36.113 に答える