1

Could any one help me to add entry at the end of the line.

This is linux os.

Below is the contents of the file /boot/grub2/grub.cfg

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Red Hat Enterprise Linux Server (3.10.0-327.el7.x86_64) 7.2 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_64-advanced-75a4fe9b-ade6-4db0-a19c-e2dce64b4f2f' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  0ee3bceb-d7b7-4e56-ae16-a17ed5f395ea
        else
          search --no-floppy --fs-uuid --set=root 0ee3bceb-d7b7-4e56-ae16-a17ed5f395ea
        fi
        linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=UUID=75a4fe9b-ade6-4db0-a19c-e2dce64b4f2f ro crashkernel=auto rhgb quiet LANG=en_US.UTF-8
        initrd16 /initramfs-3.10.0-327.el7.x86_64.img
}
menuentry 'Red Hat Enterprise Linux Server (0-rescue-3b0570b9c0c44fd7b8426ed7d80f55ff) 7.2 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-3b0570b9c0c44fd7b8426ed7d80f55ff-advanced-75a4fe9b-ade6-4db0-a19c-e2dce64b4f2f' {
        load_video
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  0ee3bceb-d7b7-4e56-ae16-a17ed5f395ea
        else
          search --no-floppy --fs-uuid --set=root 0ee3bceb-d7b7-4e56-ae16-a17ed5f395ea
        fi
        linux16 /vmlinuz-0-rescue-3b0570b9c0c44fd7b8426ed7d80f55ff root=UUID=75a4fe9b-ade6-4db0-a19c-e2dce64b4f2f ro crashkernel=auto rhgb quiet
        initrd16 /initramfs-0-rescue-3b0570b9c0c44fd7b8426ed7d80f55ff.img
}

I need to add entry at the end of the line "text1" and "text2".

linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=UUID=75a4fe9b-ade6-4db0-a19c-e2dce64b4f2f ro crashkernel=auto rhgb quiet LANG=en_US.UTF-8 text1 text2

after edit my file should look like:

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Red Hat Enterprise Linux Server (3.10.0-327.el7.x86_64) 7.2 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_64-advanced-75a4fe9b-ade6-4db0-a19c-e2dce64b4f2f' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  0ee3bceb-d7b7-4e56-ae16-a17ed5f395ea
        else
          search --no-floppy --fs-uuid --set=root 0ee3bceb-d7b7-4e56-ae16-a17ed5f395ea
        fi
        linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=UUID=75a4fe9b-ade6-4db0-a19c-e2dce64b4f2f ro crashkernel=auto rhgb quiet LANG=en_US.UTF-8 text1 text2
        initrd16 /initramfs-3.10.0-327.el7.x86_64.img
}
menuentry 'Red Hat Enterprise Linux Server (0-rescue-3b0570b9c0c44fd7b8426ed7d80f55ff) 7.2 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-3b0570b9c0c44fd7b8426ed7d80f55ff-advanced-75a4fe9b-ade6-4db0-a19c-e2dce64b4f2f' {
        load_video
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  0ee3bceb-d7b7-4e56-ae16-a17ed5f395ea
        else
          search --no-floppy --fs-uuid --set=root 0ee3bceb-d7b7-4e56-ae16-a17ed5f395ea
        fi
        linux16 /vmlinuz-0-rescue-3b0570b9c0c44fd7b8426ed7d80f55ff root=UUID=75a4fe9b-ade6-4db0-a19c-e2dce64b4f2f ro crashkernel=auto rhgb quiet
        initrd16 /initramfs-0-rescue-3b0570b9c0c44fd7b8426ed7d80f55ff.img
}
Mike Best
  • 13
  • 2
  • 5
    Can't you come up with a much more minimal (as in [mcve]) example where the difference between the input and output would be much clearer? – Ed Morton Sep 03 '17 at 18:36
  • This [question and answer](https://stackoverflow.com/questions/9591744/add-to-the-end-of-a-line-containing-a-pattern-with-sed-or-awk) is related. – Mox Sep 03 '17 at 18:40
  • @all, I thought to provide more info..As suggested i will improve and provide minimal info. – Mike Best Sep 03 '17 at 18:55
  • For this case it's easier to edit `/etc/sysconfig/grub` or `/etc/default/grub` and append like `GRUB_CMDLINE_LINUX="... text1 text2"`, followed by `grub2-mkconfig -o /boot/grub2/grub.cfg`. – Christophe Morio Sep 03 '17 at 21:03

1 Answers1

2

With sed expression:

sed '\~linux16 /vmlinuz-3\.10\.0-327\.el7\.x86_64~{s/$/ text1 text2/;}' /boot/grub2/grub.cfg
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
  • @RomanPerekhrest, Thanks a lot for the reply..I want to add text in same line at the end and not in next line – Mike Best Sep 03 '17 at 18:54