LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 08: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, 07:07 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:07 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