2

rpm automatically place a new installed kernel as the first option. However, I want to move it as the last one - to end of the file.

Grub configuration file looks like this:

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

My goal is to move first option (217.2.3) to end. Now I figure out how to delete it:

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

p command only prints current line (not as in vim, where it means paste).

Do you have any ideas how to automatically move this part of file to its end?

4

2 回答 2

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
于 2009-08-17T11:41:48.597 回答
0

一个非常相似的任务被广泛地覆盖在这里

是的,精心设计的 sed 命令会带来一些满足感,但我想我会倾向于使用编辑器,这样我就可以看到要移动的行,而不必担心在命令。

于 2009-08-17T12:15:46.073 回答