LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-26-2010, 11:52 AM   #1
webhope
Member
 
Registered: Apr 2010
Posts: 184

Rep: Reputation: 30
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
 
Old 05-26-2010, 07:21 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Read the following - http://www.gnu.org/manual/gawk/html_...ring-Functions
Specifically the sections on sub/gsub/gensub
 
Old 05-27-2010, 02:57 AM   #3
webhope
Member
 
Registered: Apr 2010
Posts: 184

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by grail View Post
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?

Last edited by webhope; 05-27-2010 at 04:13 AM.
 
Old 05-27-2010, 05:52 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Specific result of awk script jeesun Programming 3 01-24-2010 05:42 AM
How to use variables in search pattern in gensub function of awk rajeshksv Linux - Newbie 1 08-07-2009 07:07 AM
problem exporting result of awk to an array... mitramcc Linux - Newbie 2 02-10-2009 11:47 AM
using awk on a awk result jpgauvin Programming 1 12-15-2008 03:57 AM
cannot export result from awk into a variable in a bash script Emmanuel_uk Linux - Newbie 4 03-07-2005 01:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration