I read through the manpage of Sed, but I still find it quite confusing, so I hope to find some answers here :)I need to edit a file using a bash script.I need to place a couple of lines after a specific line inside grub.cfg. For the purpose of showing an example, I will add 5 newly added lines.Original:if loadfont /boot/grub/font.pf2 ; then    set gfxmode=auto    insmod efi_gop    insmod efi_uga    insmod gfxterm    terminal_output gfxtermfiset menu_color_normal=white/blackset menu_color_highlight=black/light-graymenuentry Install Ubuntu Server {    set gfxpayload=keep    linux   /install/vmlinuz  file=/cdrom/preseed/ubuntu-server.seed quiet ---    initrd  /install/initrd.gz}menuentry OEM install (for manufacturers) {    set gfxpayload=keep    linux   /install/vmlinuz  file=/cdrom/preseed/ubuntu-server.seed quiet oem-config/enable=true ---    initrd  /install/initrd.gz}After edit:if loadfont /boot/grub/font.pf2 ; then    set gfxmode=auto    insmod efi_gop    insmod efi_uga    insmod gfxterm    terminal_output gfxtermfiset menu_color_normal=white/blackset menu_color_highlight=black/light-graynewly_addedd_line_1newly_addedd_line_2newly_addedd_line_3newly_addedd_line_4newly_addedd_line_5menuentry Install Ubuntu Server {    set gfxpayload=keep    linux   /install/vmlinuz  file=/cdrom/preseed/ubuntu-server.seed quiet ---    initrd  /install/initrd.gz}menuentry OEM install (for manufacturers) {    set gfxpayload=keep    linux   /install/vmlinuz  file=/cdrom/preseed/ubuntu-server.seed quiet oem-config/enable=true ---    initrd  /install/initrd.gz}How would that work using sed? Ideally I would have all the new lines inside a new script variable.For example:LINES_TO_ADD='newly_addedd_line_1\nnewly_addedd_line_2\nnewly_addedd_line_3\nnewly_addedd_line_4\nnewly_addedd_line_5'Thank you in advance!
Sed placing text after a certain line
linux;text processing;sed;grub
sed '/^set menu_color_highlight/a\newly_addedd_line_2\newly_addedd_line_3\newly_addedd_line_4\newly_addedd_line_5' /path/to/fileOnce you have verified the output, you can use sed --in-place or write to a new file and swap the old version out.From the manual: [1addr]a\ text    Write text to standard output immediately before each attempt to read         a line of input, whether by executing the ``N'' function or by beginning         a new cycle.Possibly slightly more robustly, you can put your new block of text into a file (e. g. newlines), and then use:sed '^set menu_color_highlight/r newlines' /path/to/input.Again, from the manual: [1addr]r file         Copy the contents of file to the standard output immediately before the         next attempt to read a line of input.  If file cannot be read for any         reason, it is silently ignored and no error condition is set.