My fstab is somewhat like the following:
UUID=somevalue1
UUID=somevalue2
I want to edit the 2nd UUID. How do I do that using sed?
So after editing the fstab would look like follows:
UUID=somevalue1
UUID=somevalue3
Any help would be really appreciated
If you know somevalue2
, then you can just do something like
VALUETOREPLACE='somevalue2'
sed "s/^UUID=$VALUETOREPLACE$/UUID=somevalue3/" </etc/fstab
If you don't know, you can just do the replacement 2nd time UUID=
is found in the fstab:
sed ':a;N;$!ba;s/UUID=[A-Fa-f0-9-]*/UUID=somevalue3/2' </etc/fstab
You can try changing that 2
to 3
or anything else select another n-th match. Also note that on modern systems /etc/fstab frequently has this line in it:
# device; this may be used with UUID= as a more robust way to name devices
which also happens to have UUID=
in it and that may mess your numbering.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With