LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 12-27-2007, 04:40 AM   #1
ratul_11
LQ Newbie
 
Registered: Dec 2005
Posts: 29

Rep: Reputation: 15
Pattern Matching Problem


Hi all

I want to assign the each column of the following file in a separate variable.

2864 oracle 0.0 0.2 /home/oracle/u01/app/oracle/product/10.2.0/db_1/inventory/bin/tnslsnr LISTENER -inherit
2872 oracle 0.0 0.6 ora_pmon_orcl
2874 oracle 0.0 0.5 ora_psp0_orcl
2876 oracle 0.0 1.2 ora_mman_orcl
2878 oracle 0.0 4.4 ora_dbw0_orcl
2880 oracle 0.0 1.7 ora_lgwr_orcl
2882 oracle 0.0 1.0 ora_ckpt_orcl
2884 oracle 0.0 5.0 ora_smon_orcl
2886 oracle 0.0 0.8 ora_reco_orcl
2888 oracle 0.0 2.3 ora_cjq0_orcl
2890 oracle 0.0 4.7 ora_mmon_orcl
2892 oracle 0.0 0.7 ora_mmnl_orcl
2894 oracle 0.0 0.5 ora_d000_orcl
2896 oracle 0.0 0.5 ora_s000_orcl
2904 oracle 0.0 0.5 ora_qmnc_orcl
2922 oracle 0.0 2.2 ora_q000_orcl
2924 oracle 0.0 0.5 ora_q001_orcl
20186 oracle 0.0 5.3 oracleorcl (LOCAL=NO)
22556 root 0.0 0.1 sshd: oracle [priv]
22558 oracle 0.0 0.0 sshd: oracle@pts/7
22559 oracle 0.0 0.0 -bash
22877 oracle 0.0 0.9 ora_j000_orcl

For this I used the following code

#!/usr/bin/perl -w

@arr1 = qw/java oracle/;
@arr2 = `ps -eo pid,user,pcpu,pmem,args | grep -v grep | grep $arr1[1]`;
$length= $#arr2;

for($i=0;$i<=$length;$i++)
{
chomp;
$val=$arr2[$i];
#print $val."\n";
@arr = split(/\s+/,$val);
print $arr[1]."\n";

But I am not getting the desired output.

Thanks & Regards in advance
Anirban Adhikary.
 
Old 12-27-2007, 04:45 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,696
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
what is your desired results!?
 
Old 12-27-2007, 06:09 PM   #3
angrybanana
Member
 
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
If I'm understanding you correctly, you want to do something like this.
Code:
#!/usr/bin/perl

use strict;
use warnings;

my (@keywords, $search, @output, @filtered, @columns);

@keywords = qw/java oracle/;
@output = `ps -eo pid,user,pcpu,pmem,args`;

$search = join '|', @keywords;
@filtered = grep /$search/, @output;

for (@filtered){
        chomp;
        s/^\s+//;
        @columns = split /\s+/, $_, 5;
        print "$columns[4]\n";
}
 
Old 12-28-2007, 12:27 AM   #4
ratul_11
LQ Newbie
 
Registered: Dec 2005
Posts: 29

Original Poster
Rep: Reputation: 15
Thanks you angrybanana u r right that kind of sloution I have needed.

Wish u a happy new year

Regards
Anirban Adhikary.
 
  


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 nadeemr Linux - Newbie 8 06-13-2007 11:05 AM
Sed pattern matching digitalbrutus Programming 1 08-20-2006 01:37 PM
pattern matching problem in sed digitalbrutus Programming 4 08-20-2006 04:40 AM
Perl pattern matching in VB rigel_kent Programming 1 05-30-2006 11:00 AM
pattern matching in perl ludeKing Programming 9 04-02-2004 09:53 AM


All times are GMT -5. The time now is 07:50 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration