LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   awk - gensub first result (https://www.linuxquestions.org/questions/programming-9/awk-gensub-first-result-810247/)

webhope 05-26-2010 11:52 AM

awk - gensub first result
 
Hi,
I have this code:
Code:

block='kernel (hd0,2)/boot/vmlinuz BOOT_IMAGE=linux root=UUID=eab515e9-bc3e-4024-9f01-55fddaa0fb1c  resume=UUID=e12487ff-6d6f-44c4-9e03-33f545b3b798 splash=silent vga=788'
echo "$block" | awk '/.*UUID=/{ x=gensub(/.*UUID=([-0-9a-fA-F]+)[ )].*/,"\\1",1);  print x}'

I need to return the 1st uuid not the second as it did. Where I have a mistake?
Thanks

grail 05-26-2010 07:21 PM

Read the following - http://www.gnu.org/manual/gawk/html_...ring-Functions
Specifically the sections on sub/gsub/gensub

webhope 05-27-2010 02:57 AM

Quote:

Originally Posted by grail (Post 3982350)
Read the following - http://www.gnu.org/manual/gawk/html_...ring-Functions
Specifically the sections on sub/gsub/gensub

I have read about gensub in this manual before I asked this question. I also read about sub and gsub in other awk manual. So where do you want to direct me?

grail 05-27-2010 05:52 AM

Well I had already directed you, but it appears it did not work. So I will do the work for you:
Quote:

sub(regexp, replacement [, target])
The sub function alters the value of target. It searches this value, which is treated as a string, for the leftmost, longest substring matched by the regular expression regexp.


All times are GMT -5. The time now is 12:05 AM.