使用法: sed [オプション]... {スクリプト(他になければ)} [入力ファイル]...
-n, --quiet, --silent
suppress automatic printing of pattern space
-e スクリプト, --expression=スクリプト
実行するコマンドとしてスクリプトを追加
-f スクリプト・ファイル, --file=スクリプト・ファイル
実行するコマンドとしてスクリプト・ファイルの内容を追加
--follow-symlinks
follow symlinks when processing in place; hard links
will still be broken.
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied).
The default operation mode is to break symbolic and hard links.
This can be changed with --follow-symlinks and --copy.
-c, --copy
use copy instead of rename when shuffling files in -i mode.
While this will avoid breaking links (symbolic or hard), the
resulting editing operation is not atomic. This is rarely
the desired mode; --follow-symlinks is usually enough, and
it is both faster and more secure.
-l N, --line-length=N
「l」コマンド用の行折返し長を指定
--posix
GNU拡張を全部禁止。
-r, --regexp-extended
スクリプトで拡張正規表現を使用。
-s, --separate
ファイルを一連の入力にせず、別々に処理。
-u, --unbuffered
入力ファイルから極小のデータを取り込み、
ちょくちょく出力バッファーに掃出し
--help この説明を表示して終了
--version バージョン情報を表示して終了
-e、--expression、-f、--fileオプションのどれもないと、オプション以外の
最初の引数をsedスクリプトとして解釈します。残りの引数は全部、入力ファ
イル名となります。入力ファイルの指定がないと、標準入力を読み込みます。
GNU sed home page:
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place; hard links
will still be broken.
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied).
The default operation mode is to break symbolic and hard links.
This can be changed with --follow-symlinks and --copy.
-c, --copy
use copy instead of rename when shuffling files in -i mode.
While this will avoid breaking links (symbolic or hard), the
resulting editing operation is not atomic. This is rarely
the desired mode; --follow-symlinks is usually enough, and
it is both faster and more secure.
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-r, --regexp-extended
use extended regular expressions in the script.
-s, --separate
consider files as separate rather than as a single continuous
long stream.
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
--help display this help and exit
--version output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
GNU sed home page:
SED(1) SED(1)
名前
sed - ストリームエディタ
書式
sed [-n] [-V] [--quiet] [--silent] [--version] [--help]
[-e script] [--expression=script]
[-f script-file] [--file=script-file]
[script-if-no-other-script]
[file...]
説明
sed はストリームエディタである。ストリームエディタは、入力ストリーム (
ファイルまたはパイプラインからの入力) に対して基本的なテキスト変換を 行
う ために用いられる。 sed は編集スクリプトを使える (ed のような) エディ
タといろいろな面で似ているが、 sed は入力に対して 1 パスだけで動作す る
ので、より効率的である。また sed はパイプラインのテキストに対してフィル
タ動作を行うことができ、この点は他のタイプのエディタとはっきり違う。
オプション
sed の起動時には以下のコマンドラインオプションを指定できる。
-V
--version
sed のバージョン・著作権表示を出力し、終了する。
-h
--help コマンドラインオプションを簡単にまとめた利用法とバグレポート先の
アドレスを出力し、終了する。
-n
--quiet
--silent
デ フォルトでは、 sed はスクリプトの各サイクルの最後でパターンス
ペースの内容を出力する。これらのオプションを指定するとこの自動的
な 出力が行われなくなり、 p コマンドで出力することを指定された場
合に限って sed は出力を生成する。
-e script
--expression=script
script のコマンドを、入力の処理中に行われるコマンドセットに追 加
する。
-f script-file
--file=script-file
フ ァイル script-file に含まれるコマンドを、入力の処理中に行われ
るコマンドセットに追加する。
-e, -f, --expression, --file などのオプションがコマンドラインから全く与
え られなかった場合は、コマンドラインの引き数のうち、オプションでない最
初のものが script として受け取られ、実行される。
以上のコマンドラインパラメータを処理したあとに引き数が残った場合は、 そ
れらは処理対象となる入力ファイルのファイル名と解釈される。 - というファ
イル名は、標準入力ストリームを参照する。ファイル名が全く指定されなか っ
た場合は標準入力を処理する。
コマンドの文法
こ れは sed コマンドのごく簡単な文法で、既に sed を知っている人に対する
備忘録程度のものである。完全な記述を求める場合は他の文書 (texinfo 文 書
など) にあたること。
アドレスを取らないコマンド
: label
b コマンドと t コマンド用のラベル。
#comment
次 の改行文字まで (あるいは -e スクリプトフラグメントの末尾まで)
をコメントとして取り扱う。
} { } ブロックの閉じ括弧。
アドレスを 0 または 1 個とるコマンド
= 現在の行番号を表示する。
a \
text text を追加する。 text に改行を含めたい場合は、その前にバック ス
ラッシュを置く。
i \
text text を挿入する。 text に改行を含めたい場合は、その前にバックス
ラッシュを置く。
q これ以上入力の処理を行わず、ただちに sed スクリプトの処理を終 了
する。ただし auto-print が diable されていなければ、カレントのパ
ターンスペースが出力される。
r filename
テキストを filename から読んで追加する。
アドレス範囲をとりうるコマンド
{ コマンドブロックの開始 (} で終了する)。
b label
label に分岐する。 label が省略された場合は、スクリプトの末尾 に
分岐する。
t label
最 後に入力行が読まれ、最後に t コマンドが行われて以降に s/// が
成功していれば、 label に分岐する。 label が省略された場合は、ス
クリプトの末尾に分岐する。
c \
text 選択した行を text で置換する。 text に改行を含めたい場合は、その
前にバックスラッシュを置く。
d パターンスペースを削除する。次のサイクルを開始する。
D パターンスペースの最初の改行までを削除する。次のサイクルを開始す
るが、パターンスペースにまだデータが残っていたら、入力からの読み
込みをスキップする。
h H パターンスペースをホールドスペースにコピー/追加する。
g G ホールドスペースをパターンスペースにコピー/追加する。
x ホールドスペースとパターンスペースの内容を交換する。
l 現在の行を「視覚的に紛れのない」形式でリストする。
n N 入力の次の行をパターンスペースに読み込む/追加する。
p 現在のパターンスペースを出力する。
P 現在のパターンスペースの最初の改行までを出力する。
s/regexp/replacement/
パターンスペースに対して regexp のマッチを試みる。マッチに成功す
ると、マッチした部分を replacement に置換する。 replacement は特
殊文字である & を含むことができ、これはパターンスペースのマッ チ
した部分を参照する。また \1 から \9 までの特殊エスケープを含むこ
ともでき、これは regexp の副表現 (sub-expression) にマッチした部
分をそれぞれ参照する。
w filename
現在のパターンスペースを filename に書く。
y/source/dest/
パターンスペースにある文字のうち、 source にあるものを、 dest の
同じ位置にある文字に交換する。
アドレス
sed のコマンドはアドレスを指定せずに与えることもでき、この場合そのコ マ
ン ドはすべての入力行に対して実行される。アドレスをひとつ与えると、コマ
ンドはそのアドレスにマッチした入力行に対してのみ実行される。 2 つのアド
レスを与えると、最初のアドレスにマッチした行から、 2 番目のアドレスにマ
ッチした行に至る範囲 (両マッチ行を含む) にあるすべての行に対して実行 さ
れる。アドレスの範囲指定については 3 つのことを注意しておく。まず指定方
法は addr1,addr2 である (つまりアドレスをコンマで区切る)。 addr1 にマッ
チした行は、たとえ addr2 がより前の行にマッチした場合でも、常に処理対象
となる。 addr2 が regexp (正規表現) の場合には、 addr1 にマッチした行に
対しては addr2 のマッチは行われない。
ア ドレス (あるいはアドレス範囲) とコマンドの間には ! を挟むことができ
る。この場合は、アドレス (あるいはアドレス範囲) がマッチしなかった行 に
対してのみコマンドが実行される。
以下のアドレスタイプがサポートされている。
number number で指定した行だけにマッチする。
first~step
first 行からはじまる step 行おきの行にマッチする。例えば ‘‘sed
-n 1~2p’’ は入力行のうち奇数行を表示し、アドレスを 2~5 にする と
、第 2 行から 5 行おきに表示する (これは GNU の拡張である)。
$ 最終行にマッチする。
/regexp/
正規表現 regexp にマッチした行にマッチする。
\cregexpc
正 規表現 regexp にマッチした行にマッチする。文字 c は何でもよい
。
正規表現
POSIX.2 BRE をサポートすべきであるが、まだ完全にはサポートできていな い
。正規表現内部の \n シーケンスは改行文字にマッチする。 GNU 拡張も存在す
る。 [要修正: より詳細を記述する必要がある。少なくとも、何がサポート さ
れているかを述べた、他の文書へのリファレンスが必要である]
その他の注意
こ の バ ー ジ ョ ン の sed は、あらゆる正規表現の内部・置換コマンドの
replacement の内部・文字交換 (y) コマンドの source および dest の内部の
いずれにおいても、 \
SED(1) User Commands SED(1)
NAME
sed - stream editor for filtering and transforming text
SYNOPSIS
sed [OPTION]... {script-only-if-no-other-script} [input-file]...
DESCRIPTION
Sed is a stream editor. A stream editor is used to perform basic text
transformations on an input stream (a file or input from a pipeline).
While in some ways similar to an editor which permits scripted edits
(such as ed), sed works by making only one pass over the input(s), and
is consequently more efficient. But it is sed’s ability to filter text
in a pipeline which particularly distinguishes it from other types of
editors.
-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place; hard links will still
be broken.
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied). The
default operation mode is to break symbolic and hard links.
This can be changed with --follow-symlinks and --copy.
-c, --copy
use copy instead of rename when shuffling files in -i mode.
While this will avoid breaking links (symbolic or hard), the
resulting editing operation is not atomic. This is rarely the
desired mode; --follow-symlinks is usually enough, and it is
both faster and more secure.
-l N, --line-length=N
specify the desired line-wrap length for the ‘l’ command
--posix
disable all GNU extensions.
-r, --regexp-extended
use extended regular expressions in the script.
-s, --separate
consider files as separate rather than as a single continuous
long stream.
-u, --unbuffered
load minimal amounts of data from the input files and flush the
output buffers more often
--help display this help and exit
--version
output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
GNU sed home page:
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa