views:

48

answers:

2

Hi,

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?

+1  A: 

I have to answer myself. :-)

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

If you are not fluent with sed (me neither), there is more verbose version

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
iyo
A: 

A very similar task was covered extensively here

Yes, there is some satisfaction in a well crafted sed command, but I think I would tend to use an editor, so I could see the lines I was going to move around, and not have to worry about getting the line numbers wrong in a command.

pavium