「Sed」の版間の差分
提供: Wikinote
| 行1: | 行1: | ||
| − | * 基本構文 | + | |
| + | == 参考リンク == | ||
| + | * [http://www.gnu.org/software/sed/manual/sed.html sed, a stream editor] | ||
| + | ** 本家のオンラインマニュアル。 | ||
| + | * [http://www.grymoire.com/Unix/Sed.html Sed - An Introduction and Tutorial] | ||
| + | ** そこそこ網羅されている。 | ||
| + | |||
| + | == 基本構文 == | ||
sed [-n] [-e command] [-f command_file] [file ...] | sed [-n] [-e command] [-f command_file] [file ...] | ||
; -n | ; -n | ||
2009年2月19日 (木) 01:05時点における版
参考リンク
- sed, a stream editor
- 本家のオンラインマニュアル。
- Sed - An Introduction and Tutorial
- そこそこ網羅されている。
基本構文
sed [-n] [-e command] [-f command_file] [file ...]
- -n
- マッチしなかったら表示しない
- アドレス
-
n- n 行目のみ (最終行 : $) -
m,n- m 行目から n 行目まで -
n,/str/- n 行目から str がマッチする行まで
- ※ アドレスの後に
!を付けると否定
-
- コマンド
- p - 出力
- d - 削除
-
$ sed -e '/begin/,/end/d' FILE- begin を含む行から end を含む行までを削除
-
- y - 一文字置換 (tr コマンドと一緒)
-
$ sed -e 'y/12/ab/' FILE- FILE 中の 1 を a に、2 を b に置換 - g フラグなしでも、すべての文字に適用される
-
- s - 置換
-
$ sed -e 's/foo/bar/g' FILE- foo を bar に置換
-
- q - 終了
- フラグ
- g - 同一行中のマッチをすべて置換
- 特殊記号
- & - マッチした文字列
-
$ sed -e 's/[0-9]*/(&)/g' FILE- 数字に括弧をつける
-
- ( ), \n - パタン部分指定
-
$ sed -e 's/\(A\) \(B\)/\2 \1/g' FILE- A と B の位置を入れ替える
-
- & - マッチした文字列