
/a/b/f/g/d/g
vimの長いパスをテキストファイルの他の長いパスに置き換えたいと思います。/s/g/w/d/g/r
一般的に使用します\/
が、ここではスラッシュが多すぎます。より簡単な方法がありますか?
答え1
/
代替コマンドの区切り文字として、スラッシュの代わりに他の文字を使用できます。
使用例#
:
:%s#/a/b/f/g/d/g#/s/g/w/d/g/r#
答え2
たぶんsedを使うことができます
例 1 – sed
@
区切り記号:/opt/omni/lbin
次に置換/opt/tools/bin
パス名をに変更すると、区切り文字として代わりに
/
使用できます。以下のsedの例では、入力ファイルの最後の行が 。@
/
/opt/omni/lbin
/opt/tools/bin
$ sed 's@/opt/omni/lbin@/opt/tools/bin@g' path.txt /usr/kbos/bin:/usr/local/bin:/usr/jbin/:/usr/bin:/usr/sas/bin /usr/local/sbin:/sbin:/bin/:/usr/sbin:/usr/bin:/opt/omni/bin: /opt/tools/bin:/opt/omni/sbin:/root/bin
から:http://www.thegeekstuff.com/2009/10/unix-sed-tutorial-advanced-sed-substitution-examples/