Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

perl script to spilit data

Hi
Please have a look at simple perl code

the output is like this

mysql     1041  0.3  4.3 141588 22604 ?        Sl   09:15   0:50 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
www-data   904  0.0  2.2  41124 11660 ?        S    09:15   0:01 /usr/sbin/apache2 -k start
www-data  2739  0.0  2.2  41008 11344 ?        S    10:14   0:00 /usr/sbin/apache2 -k start
www-data  2774  0.0  2.0  39972 10308 ?        S    10:15   0:00 /usr/sbin/apache2 -k start
www-data   911  0.0  1.9  39972 10044 ?        S    09:15   0:00 /usr/sbin/apache2 -k start
www-data   910  0.0  1.9  39972 10044 ?        S    09:15   0:00 /usr/sbin/apache2 -k start
www-data   909  0.0  1.9  39972 10044 ?        S    09:15   0:00 /usr/sbin/apache2 -k start
www-data   906  0.0  1.9  39712 10076 ?        S    09:15   0:00 /usr/sbin/apache2 -k start
www-data  2754  0.0  1.9  39972  9976 ?        S    10:15   0:00 /usr/sbin/apache2 -k start
www-data  2753  0.0  1.9  39716 10052 ?        S    10:15   0:00 /usr/sbin/apache2 -k start
www-data  2742  0.0  1.8  39716  9720 ?        S    10:14   0:00 /usr/sbin/apache2 -k start
root       827  0.0  1.7  37492  9128 ?        Ss   09:14   0:04 /usr/sbin/apache2 -k start
root@IT-wiki:~/perl#


(a) I need to get the 3rd,4th and 11th column in 3 variables

(b) then put those 3 variables into a database..

can any one please help me ...
thanks


#/usr/bin/perl



open (PS_O, "ps aux | sort -nr -k 4 | head -12 |");
#open (PS_O, "ps auxf | ");

#print STDOUT <PS_O>;
while ($line = <PS_O>){

print  "$line";


}

Open in new window

0
fosiul01
Asked:
fosiul01
1 Solution
 
farzanjCommented:
Since you are using shell and pipes, you could get the relevant columns by doing one more pipe like
 | awk '{print $3" "$4" "$11}'
0
 
fosiul01Author Commented:
hi thanks

but bellow lines does not work

open (PS_O, "ps aux | sort -nr -k 4 | head -12 | awk '{print "$3" "$4" "$11"} '");


its throws too much error
0
 
fosiul01Author Commented:
ok this line does not throuw any error

open (PS_O, "ps aux | sort -nr -k 4 | head -12 | awk '{print $3 $4 $11}'");


but it does not show any oput ..
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
farzanjCommented:
Did you try this:
open (PS_O, "ps aux | sort -nr -k 4 | head -12 | awk '{print "$3\" \"$4\" \"$11} ' | ");
0
 
fosiul01Author Commented:
ok i did this

open (PS_O, "ps aux | sort -nr -k 4 | head -12 | awk '{print \"$3\" \"$4\" \"$11} ' | ");

but it saying

awk: line 1: runaway string constant "}  ...
0
 
FishMongerCommented:
0
 
wilcoxonCommented:
open (PS_O, "ps aux | sort -nr -k 4 | head -12 | awk '{print \"$3\" \"$4\" \"$11} ' | ");

is missing the \" after $11 and before the }
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now