1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-07-04 06:35:23 +02:00
tldr/pages.ja/linux/sed.md

34 lines
1.2 KiB
Markdown
Raw Normal View History

# sed
> スクリプタブルな方法でテキストを編集します。
> `awk`, `ed` も参照してください。
> もっと詳しく: <https://www.gnu.org/software/sed/manual/sed.html>。
- 全ての入力行の `apple` (基本正規表現)を `mango` (基本正規表現)に置換し、結果を`stdout`に出力する:
`{{command}} | sed 's/apple/mango/g'`
- 全ての入力行で出現する全ての `apple` (拡張正規表現)を `APPLE` (拡張正規表現)に置換し、結果を`stdout`に出力する:
`{{command}} | sed {{[-E|--regexp-extended]}} 's/(apple)/\U\1/g'`
- 特定のファイルに出現する全ての `apple` (基本正規表現)を `mango` (基本正規表現)に置換し、元のファイルを上書きする:
`sed {{[-i|--in-place]}} 's/apple/mango/g' {{path/to/file}}`
2025-06-07 15:24:03 +02:00
- 特定のスクリプトファイルを実行し、結果を`stdout`に出力する:
2025-06-07 15:24:03 +02:00
`{{command}} | sed {{[-f|--file]}} {{path/to/script.sed}}`
- 最初の行だけを`stdout`に出力する:
`{{command}} | sed {{[-n|--quiet]}} '1p'`
2025-06-07 15:24:03 +02:00
- ファイルの最初の行を削除する:
`sed {{[-i|--in-place]}} 1d {{path/to/file}}`
2025-06-07 15:24:03 +02:00
- ファイルの先頭行に改行を挿入する:
`sed {{[-i|--in-place]}} '1i\your new line text\' {{path/to/file}}`