题
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中,在其中表示粘贴)。
您有什么想法如何将文件的这一部分自动移动到最后?
解决方案
我必须回答自己。 :-)
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
其他提示
一项非常相似的任务被广泛涵盖 这里
是的,精心制作的SED命令有一些满意命令。
不隶属于 StackOverflow