SEL elapsedtime ,StartTime,QueryText
FROM dbc.qry
WHERE StartTime >= '2010-03-24 20:10:08'
AND username ='xxx_yyy_aaa_01'
ORDER BY LastRespTime DESC
The output needed is just "=" which exist before 'xxx_yyy_aaa_01'
also if the same data file as below having "in"
SEL elapsedtime ,StartTime,QueryText
FROM dbc.qry
WHERE StartTime >= '2010-03-24 20:10:08'
AND username in('xxx_yyy_aaa_01')
ORDER BY LastRespTime DESC
then the output needed is just "in"..
i want to achive the resultant dynamically either = or in based on the data.
Can this be done in single statement or using pearl scripting..
$
$
$ # equal-to (=) operator not followed by space
$ cat file1.sql
SEL elapsedtime ,StartTime,QueryText
FROM dbc.qry
WHERE StartTime >= '2010-03-24 20:10:08'
AND username ='xxx_yyy_aaa_01'
ORDER BY LastRespTime DESC
$
$ perl -lne '/^(\s*\w+){2}\s*(.*?)[\s(]*.xxx_yyy_aaa_01.*$/ && print $2' file1.sql
=
$
$ # equal-to (=) operator followed by a space
$ cat file2.sql
SEL elapsedtime ,StartTime,QueryText
FROM dbc.qry
WHERE StartTime >= '2010-03-24 20:10:08'
AND username = 'xxx_yyy_aaa_01'
ORDER BY LastRespTime DESC
$
$ perl -lne '/^(\s*\w+){2}\s*(.*?)[\s(]*.xxx_yyy_aaa_01.*$/ && print $2' file2.sql
=
$
$ # IN operator followed by bracket "(" not followed by space
$ cat file3.sql
SEL elapsedtime ,StartTime,QueryText
FROM dbc.qry
WHERE StartTime >= '2010-03-24 20:10:08'
AND username in('xxx_yyy_aaa_01')
ORDER BY LastRespTime DESC
$
$ perl -lne '/^(\s*\w+){2}\s*(.*?)[\s(]*.xxx_yyy_aaa_01.*$/ && print $2' file3.sql
in
$
$ # IN operator followed by space followed by bracket "("
$ cat file4.sql
SEL elapsedtime ,StartTime,QueryText
FROM dbc.qry
WHERE StartTime >= '2010-03-24 20:10:08'
AND username in ('xxx_yyy_aaa_01')
ORDER BY LastRespTime DESC
$
$ perl -lne '/^(\s*\w+){2}\s*(.*?)[\s(]*.xxx_yyy_aaa_01.*$/ && print $2' file4.sql
in
$
$ # IN operator followed by space not followed by bracket "("
$ cat file5.sql
SEL elapsedtime ,StartTime,QueryText
FROM dbc.qry
WHERE StartTime >= '2010-03-24 20:10:08'
AND username in 'xxx_yyy_aaa_01'
ORDER BY LastRespTime DESC
$
$ perl -lne '/^(\s*\w+){2}\s*(.*?)[\s(]*.xxx_yyy_aaa_01.*$/ && print $2' file5.sql
in
$
$
Thanks a lot Tyler.. Appreciate your qucik reply ... as i have zero knowledge on Perl... hence i would like to understand how actually how the script is working.. Thanks again..
In the simplest terms, the script searches for a line that matches the regular expression pattern and prints a chunk from the pattern.
If you have zero knowledge of Perl, then you are lucky as nowadays there's a huge wealth of resources on the Internet and books etc. that can help you. Google is your friend here. Books by O'Reilly are pretty good.
I can tell you what that regex does, but it would be better if you have at least a rudimentary knowledge of terms like "metacharacters", "backreferences", "character-classes", "repetition quantifiers" before that. You may want to check out the book by Jeffrey Friedl, which is probably one of the best on regexes.
Originally Posted by nitinrp1
...
Assume i have the input file as below
Code:
SEL elapsedtime ,StartTime,QueryText
FROM dbc.qrylog
WHERE StartTime >= '2010-03-24 20:10:08'
AND username in ('tst1','xxx_yyy_drv_01')
and user = ('abc_aaa')
For the above code if i run the perl script given by its gives out put as in and =