473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Parsing a delimited text file into mysql database

Alrights....the delimited text in the topic is like this :

(Btop - 19:37:12 up 9:43, 1 user, load average: 0.20, 0.10, 0.03(B
Tasks:(B(B 105 (Btotal,(B(B 1 (Brunning,(B(B 104 (Bsleeping,(B(B 0 (Bstopped,(B(B 0 (Bzombie(B
Cpu(s):(B(B 1.4%(Bus,(B(B 1.6%(Bsy,(B(B 0.0%(Bni,(B(B 96.3%(Bid,(B(B 0.4%(Bwa,(B(B 0.3%(Bhi,(B(B 0.1%(Bsi,(B(B 0.0%(Bst(B
Mem: (B(B 515224k (Btotal,(B(B 486332k (Bused,(B(B 28892k (Bfree,(B(B 71916k (Bbuffers(B
Swap:(B(B 1048568k (Btotal,(B(B 0k (Bused,(B(B 1048568k (Bfree,(B(B 270032k (Bcached(B

 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND (B
(B 2264 root 15 0 38936 13m 6664 S 3.8 2.6 9:04.22 Xorg (B
(B(B 6206 root 15 0 2164 928 716 R 3.8 0.2 0:00.04 top (B
(B 6123 root 15 0 39976 11m 8312 S 1.9 2.3 0:00.78 gnome-terminal (B
(B 6204 root 17 0 4436 1020 904 S 1.9 0.2 0:00.01 autoscript (B
(B 1 root 15 0 2032 628 540 S 0.0 0.1 0:03.93 init (B
(B 2 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 (B
(B 3 root 34 19 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/0 (B
(B 4 root RT 0 0 0 0 S 0.0 0.0 0:00.02 watchdog/0 (B
(B 5 root 10 -5 0 0 0 S 0.0 0.0 0:00.73 events/0 (B
(B 6 root 10 -5 0 0 0 S 0.0 0.0 0:00.01 khelper (B
(B 7 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 kthread (B
(B 10 root 10 -5 0 0 0 S 0.0 0.0 0:00.14 kblockd/0 (B
(B 11 root 20 -5 0 0 0 S 0.0 0.0 0:00.00 kacpid (B
(B 65 root 17 -5 0 0 0 S 0.0 0.0 0:00.00 cqueue/0 (B
(B 68 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 khubd (B
(B 70 root 10 -5 0 0 0 S 0.0 0.0 0:00.03 kseriod (B
(B 124 root 21 0 0 0 0 S 0.0 0.0 0:00.00 pdflush (B[?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..
Apr 7 '08 #1
4 1953
ronverdonk
4,258 Expert 4TB
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
Apr 7 '08 #2
I'm sorry...

I have this line from a text file:
Expand|Select|Wrap|Line Numbers
  1. Cpu(s):(B(B 1.4%(Bus,(B(B 1.6%(Bsy,(B(B 0.0%(Bni,(B(B 96.3%(Bid,(B(B 0.4%(Bwa,(B(B 0.3%(Bhi,(B(B 0.1%(Bsi,(B(B 0.0%(Bst(B
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??
Apr 17 '08 #3
ronverdonk
4,258 Expert 4TB
Using == will work quicker, as in[php]foreach($lines as $line){
if (substr($line, 0, 3) == 'Cpu')
$teams[] = $line;
}[/php]Ronald
Apr 17 '08 #4
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...
Apr 18 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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...
1
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...
9
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...
6
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...
15
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()....
8
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...
1
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,...
22
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.