LoginSignup
10
7

More than 1 year has passed since last update.

sedの区切り文字

Last updated at Posted at 2016-08-26

※こちらの記事は個人ブログに移行しました

sedコマンドでファイルパスを置換したい時とか、
たいてい以下みたいな感じに書くと思う。

$ echo /path/to/file | sed -e 's/path\/to/path2/g'
/path2/file

/をエスケープしなければいけないのでそのままコピペできなかったり見づらかったりいろいろ面倒。

#実は...
sedの区切り文字は/じゃなくても動く。
例えば#で区切ってみる。

$ echo /path/to/file | sed -e 's#path/to#path2#g'
/path2/file

エスケープしなくていいので見やすい。

#ちなみに...
sの次の文字を区切り文字として使うのでこんな感じでも動く。

$ echo /path/to/file | sed -e 'sxpath/toxpath2xg'
/path2/file

xで区切ってみたけど、これはこれで見にくい。

10
7
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
10
7