如何将文件的一部分移动到末尾
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 中,它意味着粘贴)。
您有什么想法如何自动将文件的这一部分移动到末尾吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我必须自己回答。 :-)
如果您不熟悉 sed (我也不熟悉),还有更详细的版本
I have to answer myself. :-)
If you are not fluent with sed (me neither), there is more verbose version
广泛涵盖了一个非常相似的任务这里
是的,精心制作的 sed 命令让人感到满意,但我想我会倾向于使用编辑器,这样我就可以看到我要移动的行,而不必担心关于命令中的行号错误。
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.