2009-08-17 13 views
2

rpmは自動的に新しいインストール済みカーネルを最初のオプションとして配置します。しかし、私は最後のものとしてファイルの最後に移動したい。ファイルの一部を末尾に移動する方法

GRUB設定ファイルを次のようになります。

default=0 
timeout=5 
splashimage=(hd0,0)/grub/splash.xpm.gz 
hiddenmenu 
title Fedora (2.6.29.6-217.2.7.fc11.x86_64) 
    root (hd0,0) 
    kernel /vmlinuz-2.6.29.6-217.2.7.fc11.x86_64 ro root=/dev/mapper/main-root rhgb quiet 
    initrd /initrd-2.6.29.6-217.2.7.fc11.x86_64.img 
title Fedora (2.6.29.6-217.2.3.fc11.x86_64) 
    root (hd0,0) 
    kernel /vmlinuz-2.6.29.6-217.2.3.fc11.x86_64 ro root=/dev/mapper/main-root rhgb quiet 
    initrd /initrd-2.6.29.6-217.2.3.fc11.x86_64.img 
title Fedora (2.6.29.6-213.fc11.x86_64) 
    root (hd0,0) 
    kernel /vmlinuz-2.6.29.6-213.fc11.x86_64 ro root=/dev/mapper/main-root rhgb quiet 
    initrd /initrd-2.6.29.6-213.fc11.x86_64.img 

私の目標は終了する最初のオプション(217.2.3)を移動させることです。今、私はそれを削除する方法を見つけ出す:

sed -e '/(2.6.29.6-217.2.7.fc11.x86_64)/,+3d' /boot/grub/menu.lst 

pコマンドは(それがペーストを意味する、ではないのvimのように)現在の行を出力します。

ファイルのこの部分を自動的に最後まで移動する方法はありますか?

答えて

3

私は自分自身に答える必要があります。あなたが流暢でない場合

sed '/\(2.6.18-157.el5\)/,+4 { H; d; }; $ { p; x; }' /boot/grub/menu.lst 

は(私もない)のsedで、より詳細なバージョン

sed ' 
/\(2.6.18-157.el5\)/,+3 { #Find line which contains version of our kernel in parentheses and took also 3 following lines 
    H # Append this line into buffer 
    d # Delete line 
} 

$ { # On the last line 
p # Print current line 
x # Change current line with buffer and vice versa 
# Afterwards sed print current line => in our case deleted line 
}' /boot/grub/menu.lst 
0

がある非常によく似たタスクははい、あり広くhere

覆われていた:-) sedコマンドでうまくいくとは思っていましたが、私はエディタを使う傾向があると思いますので、私は移動したい行を見ることができ、コマンドに行番号が間違っているのを心配する必要はありません。

関連する問題