sed ストリームエディタ。
manの説明には、このように書かれています。
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.
テキストをフィルタリングするための、ストリームエディタですね。
こんな感じで使います。
フィルタ前
$ seq 10 1 2 3 4 5 6 7 8 9 10
フィルタ後
$ seq 10 | sed -e 's/$/00/' 100 200 300 400 500 600 700 800 900 1000
seq 10で生成された1〜10までの数字がsedによってフィルタリングされ、
行末に00が追加されました。
sedに渡しているs///の意味は、
s/置換前文字列/置換後文字列/
置換前が$で置換後が00だが、$は正規表現で行末の意味。
行末を何かの文字列で置換するということは、行末に文字列を追加するという意味になるんです。
このようにsedを使えばテキストのフィルタリングができます。
man sedで表示されるオプションは以下のとおりです。
-n, --quiet, --silent
suppress automatic printing of pattern space
--debug
annotate program execution
-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
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-E, -r, --regexp-extended
use extended regular expressions in the script (for portability
use POSIX -E).
-s, --separate
consider files as separate rather than as a single, continuous
long stream.
--sandbox
operate in sandbox mode (disable e/r/w commands).
-u, --unbuffered
load minimal amounts of data from the input files and flush the
output buffers more often
-z, --null-data
separate lines by NUL characters
--help
display this help and exit
--version
output version information and exit



コメント