2007年1月31日水曜日

対話型テキスト置換スクリプト?

#!/bin/bash

echo "original file="
read origtxtfile
echo "original strings="
read origstrings
echo "change strings="
read chstrings
echo "change file="
read chtxtfile
sed -e s/$origstrings/$chstrings/g $origtxtfile > $chtxtfile


change strings script
ファイル内にある一定の文字列を一定の文字列に変換して保存するスクリプト。
参考URLはhttp://memo.majide.com/index.php?%3ACategory%2FLinux
readというコマンドが、行を解釈するらしいので、
echoと組み合わせて対話的にしてみました。
最後のsedは、文字列を置換するコマンドで、構文はsed [OPTION][FILE]
"-e"は、続くscriptを処理に利用するオプション。
s以降は、s/置換する元のもの(条件や文字列)/置換したい条件や文字列/ 操作するファイル >でリダイレクトして 保存するファイル
sedの参考URLはhttp://itpro.nikkeibp.co.jp/article/COLUMN/20060227/230879/

iptablesで、eth1をeth0に書き直すのが面倒で作成。
http://www.isc.meiji.ac.jp/faq/faq-unix/contents.txt
ここで探して
http://www.nurs.or.jp/~asada/FAQ/UNIX/section2.5.html
に辿り着き
http://memo.majide.com/index.php?%3ACategory%2FLinux
を見つけた、と。

0 件のコメント:

コメントを投稿