Alrights....the delimited text in the topic is like this :
[H[2J(B[mtop - 19:37:12 up 9:43, 1 user, load average: 0.20, 0.10, 0.03(B[m[39;49m[K
Tasks:(B[m[39;49m(B[m 105 (B[m[39;49mtotal,(B[m[39;49m(B[m 1 (B[m[39;49mrunning,(B[m[39;49m(B[m 104 (B[m[39;49msleeping,(B[m[39;49m(B[m 0 (B[m[39;49mstopped,(B[m[39;49m(B[m 0 (B[m[39;49mzombie(B[m[39;49m[K Cpu(s):(B[m[39;49m(B[m 1.4%(B[m[39;49mus,(B[m[39;49m(B[m 1.6%(B[m[39;49msy,(B[m[39;49m(B[m 0.0%(B[m[39;49mni,(B[m[39;49m(B[m 96.3%(B[m[39;49mid,(B[m[39;49m(B[m 0.4%(B[m[39;49mwa,(B[m[39;49m(B[m 0.3%(B[m[39;49mhi,(B[m[39;49m(B[m 0.1%(B[m[39;49msi,(B[m[39;49m(B[m 0.0%(B[m[39;49mst(B[m[39;49m[K
Mem: (B[m[39;49m(B[m 515224k (B[m[39;49mtotal,(B[m[39;49m(B[m 486332k (B[m[39;49mused,(B[m[39;49m(B[m 28892k (B[m[39;49mfree,(B[m[39;49m(B[m 71916k (B[m[39;49mbuffers(B[m[39;49m[K
Swap:(B[m[39;49m(B[m 1048568k (B[m[39;49mtotal,(B[m[39;49m(B[m 0k (B[m[39;49mused,(B[m[39;49m(B[m 1048568k (B[m[39;49mfree,(B[m[39;49m(B[m 270032k (B[m[39;49mcached(B[m[39;49m[K
[6;1H
[7m PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND (B[m[39;49m[K
(B[m 2264 root 15 0 38936 13m 6664 S 3.8 2.6 9:04.22 Xorg (B[m[39;49m
(B[m(B[m 6206 root 15 0 2164 928 716 R 3.8 0.2 0:00.04 top (B[m[39;49m
(B[m 6123 root 15 0 39976 11m 8312 S 1.9 2.3 0:00.78 gnome-terminal (B[m[39;49m
(B[m 6204 root 17 0 4436 1020 904 S 1.9 0.2 0:00.01 autoscript (B[m[39;49m
(B[m 1 root 15 0 2032 628 540 S 0.0 0.1 0:03.93 init (B[m[39;49m
(B[m 2 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 (B[m[39;49m
(B[m 3 root 34 19 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/0 (B[m[39;49m
(B[m 4 root RT 0 0 0 0 S 0.0 0.0 0:00.02 watchdog/0 (B[m[39;49m
(B[m 5 root 10 -5 0 0 0 S 0.0 0.0 0:00.73 events/0 (B[m[39;49m
(B[m 6 root 10 -5 0 0 0 S 0.0 0.0 0:00.01 khelper (B[m[39;49m
(B[m 7 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 kthread (B[m[39;49m
(B[m 10 root 10 -5 0 0 0 S 0.0 0.0 0:00.14 kblockd/0 (B[m[39;49m
(B[m 11 root 20 -5 0 0 0 S 0.0 0.0 0:00.00 kacpid (B[m[39;49m
(B[m 65 root 17 -5 0 0 0 S 0.0 0.0 0:00.00 cqueue/0 (B[m[39;49m
(B[m 68 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 khubd (B[m[39;49m
(B[m 70 root 10 -5 0 0 0 S 0.0 0.0 0:00.03 kseriod (B[m[39;49m
(B[m 124 root 21 0 0 0 0 S 0.0 0.0 0:00.00 pdflush (B[m[39;49m[6;1H[K[25;1H[?12l[?25h
I would like to get the string with % in the line start with CPU(s) (shown Bold) and put them into a variables..
Would someone be kind enough to write a php file which will do that?
Because i know nothing about this parsing things, and just a very little knowledge about php. So the code would need to be complete i hope..
4 1953
Would someone be kind enough to write a php file which will do that?
Because i know nothing about this parsing things, and just a very little knowledge about php. So the code would need to be complete i hope..
At this forum we do not provide complete code by request!
This is a site where experts and programmers help other programmers with the code they have developed themselves or with problems they encounter while developing code.
For a complete php script you'll have to turn to a paid php programmer, not to this forum.
Ronald
I'm sorry...
I have this line from a text file: - Cpu(s):(B[m[39;49m(B[m 1.4%(B[m[39;49mus,(B[m[39;49m(B[m 1.6%(B[m[39;49msy,(B[m[39;49m(B[m 0.0%(B[m[39;49mni,(B[m[39;49m(B[m 96.3%(B[m[39;49mid,(B[m[39;49m(B[m 0.4%(B[m[39;49mwa,(B[m[39;49m(B[m 0.3%(B[m[39;49mhi,(B[m[39;49m(B[m 0.1%(B[m[39;49msi,(B[m[39;49m(B[m 0.0%(B[m[39;49mst(B[m[39;49m[K
and i have made a code to search this line and put into an array, the code is like this :
[PHP]
<?
$lines = file('cpu050420081937.txt');
$teams = array();
foreach($lines as $line){
if(preg_match('/Cpu\.\S$/',$line)){
$teams[] = $line;
}
}
?> [/PHP]
I need to find a line started with Cpu(s).
But it always return an empty array. Could somebody please help me to make it work??
Using == will work quicker, as in[php]foreach($lines as $line){
if (substr($line, 0, 3) == 'Cpu')
$teams[] = $line;
}[/php]Ronald
please correct me if i'm wrong,
[PHP]<? substr($line,0,3) == Cpu ?>[/PHP]
is to read $line from 1st character to 3rd character, and compare it to string 'Cpu'
It works, thank you...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Artco News |
last post by:
I thought I ask the scripting guru about the following.
I have a file containing records of data with the following format(first
column is the label):
CODE#1^DESCRIPTION^CODE#2^NOTES...
|
by: JStrummer |
last post by:
Any recommendations on how to generate an INSERT SQL script for the
records in a tab-delimietd text file? The limitation is that, while I
do have command-line mySQL access locally, I do not at my...
|
by: (Pete Cresswell) |
last post by:
I see this coming on a develpment effort that may materialize shortly.
These guys don't want to mess around with automated imports from text feeds BC
in the past they've had too many problems...
|
by: kevin |
last post by:
I need to parse an third party supplied delimited or fixed width text file
into a datatable. The delimiter may vary.
I am currently using a SteamReader to read each line and, for delimited...
|
by: VMI |
last post by:
I'm parsing a comma-delimited record but I want it to do something if some of
the string is between "". How can I do this? With the Excel import it does
it correct. I'm using String.Split()....
|
by: pradeepss |
last post by:
Guys,
I have a text file which is comma delimited and information. Each information is ended by end of line and started again with comma delimited i.e.
1,2,3,a,4
2,s,4,5,6,7,8,h...
|
by: Fordraiders |
last post by:
vb.net 2003
Office 2003
What I have:
C:\TestData\Input.txt
Text File Pipe Delimited : 4 columns Of data
example:
00001|NO BRAND NAME ASSIGNED|6DU27|M3-.5 X 6 FLAT HD SOCKET CAP SCREW,...
|
by: JJ |
last post by:
Whats the best way for me to pull out records from a tab delimited text
file?
Or rather HOW do I parse the text, knowing that the tabs are field
delimiters and a return (I image) signifies a new...
|
by: chixor1 |
last post by:
I have been charged with Parsing the data from many Abstract files, and then inputing this information into a SQL Database.
The file format is rather unusual and certainly not delimited in any...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |