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
h
,H
andg
orx
operation. I'll wait for more answers or choose yours if I get no more. – xpt Oct 20 '21 at 12:21multi-line pick & delete
do you mean "sed, please set address to say, line2, line4, line5 and line6, and when you set that address, delete it (those lines, 2,4,5 and 6) with 'd' at once? Are you trying to set arbitrary 'multi-non-consecutive-lines' address? Maybe you are trying to 'set up' address containing lines at your will, say address 7, 10, 15, 20to24 and 55? If that is your requirement, as I know sed cannot do that without using '-e' or ';'. – Damir Oct 20 '21 at 13:12sed '2d; 4,6d
? I'm just curious :) - why do you want/must use 'holding' sed feature? – Damir Oct 20 '21 at 14:17if
statements, and I want only to process thefeature_platform_search_hint
one. Your solution works perfectly for the sample in this case, just not what I was thinking, which I didn't make clear in the first place. accepting yours and I'll give my solution below. – xpt Oct 21 '21 at 00:30