LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

sed

Last updated at Posted at 2020-05-01

できること

  • 文字列データを置換する

基本構文

$ sed 's/置換前/置換後/'

よく使う構文

$ sed 's/置換前/置換後'

一行内の最初の置換対象のみ置換

$ sed 's/置換前/置換後/g'

一行内のすべての置換対象を置換

$ sed '行番号s/置換前/置換後/'

特定行の置換対象を置換

$ sed '開始行,終了行s/置換前/置換後/'

開始行から終了行までの置換対象を置換

$ sed '$s/置換前/置換後/'

最終行の置換対象を置換

$ sed -n '指定範囲p'

置換対象行を確認

$ sed -n '指定範囲!p'

指定行を非表示

$ sed -d '指定範囲d'

指定行を非表示

$ sed -n '1~2p'

指定行から等間隔で表示。上記は奇数行のみ表示

よく使うオプション

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up