Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-06-2009, 08:42 AM   #1
LQ Newbie
Registered: Jan 2009
Posts: 10

Rep: Reputation: 0
How to use variables in search pattern in gensub function of awk

Hii guys,

I am doing a small project where I have to parse different type of logs.I am using awk for the same.Suppose I have a variable which contains the search pattern , how do I use it in gensub function

Say I am now using this to extract the words after EXCEPTION and FAILED

a=gensub(/.*EXCEPTION(.*)FAILED(.*).*/,"\\1 \\2","s",$1);
print a;

Now I have to store this search pattern in a variable so that I can modify later.So even if log syntax changes a little bit ,my code should work provided the search pattern in variable is changed.

Can I use variables in first parameter of gensub?Thts my main question..

Plz help me

Thanks in Advance
Rajesh KSV
Old 08-07-2009, 07:07 AM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Hello Rajesh

I expect so -- would be weird if not. It's probably quicker to try it than wait for an LQ reply.




Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Pattern matching in a text file - use of AWK?? wtaicken Programming 19 02-06-2009 05:54 PM
printing like xls pattern using awk bharatbsharma Programming 6 09-12-2008 04:07 AM
How to get the pattern using sed or awk? ahpin Programming 3 08-02-2007 03:16 AM
Need ideas on how to grep for pattern using awk rahulbgl Linux - Newbie 4 03-05-2007 03:07 PM
awk print lines that doesn't have a pattern huynguye Programming 5 05-04-2006 11:08 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:07 PM.

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