sed

sed


読み方


意味

  • Stream EDitor

サンプル

  • まず、サンプルデータの登録されたファイルを作成する。
$ echo "abcdef" > sample1.txt
$ cat sample1.txt
abcdef

サンプル1

  • 以下のコマンドを実行する。
$ sed s/abc/def/ < sample1.txt > sample2.txt
  • 結果
$ cat sample2.txt
defdef

サンプル2

  • 以下のコマンドを実行する。
$ ls
perl/  sample.txt  sample1.txt  sample2.txt
$ ls | sed 's/[a-z]/x/g'
  • 結果
xxxx/
xxxxxx.xxx
xxxxxx1.xxx
xxxxxx2.xxx

サンプル3

  • 以下のコマンドを実行する。
$ cat sample1.txt | sed 's/abc/ABC/'
  • 結果
ABCdef

サンプル4

  • 以下のコマンドを実行する。
$ cat sample.txt | sed 's/\([ab]\).\([def]\)/\1X\2/g'
  • 結果
abXdef

サンプル5(perlで行う。)

  • 以下のコマンドを実行する。
$ perl -pe 's/abc/def/g' < sample1.txt
  • 結果
defdef
最終更新:2006年01月30日 02:20
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。