1月 152009
 

■置き換えた文字列を\1などに格納して表示させる
sed -e “s/条件/\1・・・・/g” ファイル名
* \1とかは自動的に振られるので、\1\2\3というかんじ。
\1,\2,というかんじに表示させることもできる。
(例)
sed -e “s/\(.\+\?\)\([a-z]*\)\(.\+\?\)/\1\2\3/g” sample2.txt
(結果)
abcd14
(sample2.txtの中身)
あいうえおabcdあ14だ
-----------------------------------—-
◎エスケープ
-----------------------------------—-
(スラッシュとかは文字列扱いの場合は\でエスケープする)
メタ文字扱いしたいのにエスケープする。。
( → \(
+ → \+
? → \?
のようにエスケープする
「*」はなぜかやらなくていい。

よく読まれている記事

この記事を読んだ人は次の記事も読んでいます:

このエントリーをはてなブックマークに追加
はてなブックマーク - 置き換えた文字列を\1などに格納して表示させる linuxコマンド
[`google_buzz` not found]
[`yahoo` not found]
[`livedoor` not found]
[`friendfeed` not found]
[`tweetmeme` not found]
[`grow` not found]
[`evernote` not found]

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)