awk regexp for uuid
I try to get uuid value from variable $block got from menu.lst
This try does not work. What is wrong? Code:
uuid=$( echo $block | awk --re-interval '/\(root=UUID=/{ x=gensub(/([0-9a-f-]{36,36})/,"\\1","g"); |
Where does "block" get assigned?
Regardless, this works: I put a section of my menu.lst into a file "uuid" Code:
[mherring@mystical play]$ more uuid |
PS:
Does anyone know if a uuid always has the same number of characters? If so, that could be incorporated into the regex. |
Yes. uuid is always in the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, that is 8-4-4-4-12 characters. There is an utility called uuidgen to generate random uuid sequences.. here are some results:
Code:
$ uuidgen |
Quote:
World = 6.8E+9 10E+38 / 6.8E+9 = ~ 1.5E+29 uuids for every man, woman, and child.....Use them wisely...;) |
The $block is just a block of lines for one OS from menu.lst . I don't access menu.lst directly. I extracted the block from one big file.
I forgot. I wanted to write a more simple rule with [^ ]* I wait till awk solution. |
W/o knowing what "$block"s content looks like it will be difficult to
ascertain whether your awk statement will match or not.... We can only guess.... Code:
'{ x=gensub(/.*([0-9a-f-]{36,36}).*/,"\\1","g"); print x} Cheers, Tink |
Quote:
|
block e.g.
Code:
title Sata Mandriva UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c UUID=e12487ff-6d6f-44c4-9e03-33f545b3b798 values... Edit My try: Code:
uuid=$( echo $block_new | awk --re-interval '/\UUID=/{ x=gensub(/([0-9a-f-]{36,36}).*/,"\\1","g"); Code:
kernel (hd0,2)/boot/vmlinuz BOOT_IMAGE=linux root=UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c I wanted to change root=UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c to root=(hd0,2) is it valid for use in menu.lst? |
Quote:
Edit Acording pixellany's menu.lst Code:
kernel /boot/vmlinuz26 root=/dev/disk/by-uuid/b48c40f6-3a7f-4498-b45c-ea68e1d11071 ro /dev/disk/by-uuid/... I have UUID=.... |
Quote:
There are two usages of "root" in the GRUB menu.lst: 1. root (hd0,2) means: "GRUB, please look in the 3rd partition of drive #1 to find your files." 2. kernel /boot/vmlinuzxyz root=/dev/sda3 ro Here, the "root" statement is a message to the kernel, telling it where to mount the filesystem. (sda3 also means 3rd partition of drive 1) The grub root and the filesystem root are not necessarily the same. |
Quote:
/dev/sda3 (Mandriva) or /dev/hda3 (Ubuntu) I look for solid solution, not changeable Edit Was is surprising for me is POST #9 CODE - line 2 - different uuids. I guess its error in my code. Is it normal to have two different uuids on one line? |
Quote:
As for the "root" explanation, there can be only one right answer for each one---you don't have a choice. Did you understand the 2 definitions? |
Quote:
Yet I have problem with the awk. Code:
uuid=$( echo $block_new | awk --re-interval '/^.*UUID=/{ x=gensub(/([0-9a-f-]{36,36}).*/,"\\1","g"); print x}') Code:
kernel (hd0,2)/boot/vmlinuz BOOT_IMAGE=linux root=UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c |
Quote:
Code:
{ x=gensub(/.*([0-9a-f-]{36,36}).*/,"\\1","g"); print x} |
All times are GMT -5. The time now is 10:27 AM. |