Given inputs in the format of
set root='hd0,gpt3'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt3 --hint-efi=hd0,gpt3 --hint-baremetal=ahci0,gpt3 dcf03c24-3d0d-4581-be1d-67b90f92a2c1
else
search --no-floppy --fs-uuid --set=root dcf03c24-3d0d-4581-be1d-67b90f92a2c1
fi
linux /boot/vmlinuz-5.4.0-33-generic root=UUID=dcf03c24-3d0d-4581-be1d-67b90f92a2c1 ro net.ifnames=0
initrd /boot/initrd.img-5.4.0-33-generic
. . .
if test x$grub_platform = xpc; then
linux_suffix=16;
else
linux_suffix= ;
fi
UPDATE:
I didn't make it clear at first. The question When will grub2's feature_platform_search_hint might be "No" has more info. I.e., there are other if statements, and I want only to process the feature_platform_search_hint one. Putting another if case above now.
I want my sed to pick the first search command under the feature_platform_search_hint condition while ignore/delete the whole if command block:
set root='hd0,gpt3'
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt3 --hint-efi=hd0,gpt3 --hint-baremetal=ahci0,gpt3 dcf03c24-3d0d-4581-be1d-67b90f92a2c1
linux /boot/vmlinuz-5.4.0-33-generic root=UUID=dcf03c24-3d0d-4581-be1d-67b90f92a2c1 ro net.ifnames=0
initrd /boot/initrd.img-5.4.0-33-generic
The rest/remaining lines are intact.
Here is the sed command that I come up with:
/feature_platform_search_hint/{
# remove if line and keep next
d; N; h;
# remove else block
N; N; N; d;
g; s/ search /search /;
}
But it is not working as I expected.
Why and how to fix? thx