LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-06-2009, 09:42 AM   #1
rajeshksv
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, 08:07 AM   #2
catkin
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.

Best

Charles
 
  


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


All times are GMT -5. The time now is 08:29 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration