R.A. Epigonos et al.

[linux] sedでn行目を削除

viを使うまでも無い編集はsedを使う。N行目を削除するようなはっきりとした目的がある場合は特に。

たとえば以下。sshで鍵が変わって37行目がおかしいよと言われた場合。

$ ssh my@192.168.13.3
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
***********************************************.
Please contact your system administrator.
Add correct host key in /**************/.ssh/known_hosts to get rid of this message.
Offending key in /**************/.ssh/known_hosts:37
RSA host key for 192.168.13.3 has changed and you have requested strict checking.
Host key verification failed.

この鍵を削除するには以下のようにして、-iと-e 'd'を使う。-iは変更内容を引数のファイルに書き込むオプション

$ sed -i -e '37d' /**************/.ssh/known_hosts

リファレンス

  1. sed - ストリーミングエディタ

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2010-06-05T05:00:27+09:00
  2. Modified: 2010-06-05T05:00:27+09:00
  3. Generated: 2023-08-27T23:09:12+09:00