473,387 Members | 1,742 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,387 software developers and data experts.

Sorting Massive amounts of Data

Hi there.

I've got some data currently stored in an Excel table, or a notepad
file depending on which would be easier to work with.. Im assuming
notepad(.txt) so that data can be read into php.

Anyway, this data is majorly corrupted and contains stuff i dont need.
For instance, a sample line is:

MNs73dd78INFORMATION I NEED 32427 12759 39384425 495242 15.206412
0.191214 44.164503 -93.993798

As you can see, its pretty messed up. I only need the "INFORMATION I
NEED" part, not the 9 characters before, nor any numbers or decimal
places afterwards.

I cant do this manually, as there are tens of thounsands of records.

Any ideas how I could go about this please.

Im assuming I would some how remove the first 9 characters, and then
some how remove all numbers and decimal places, but i've got no idea
how to go about it.

Kind Regards

Nov 15 '06 #1
4 1056
Advo wrote:
Hi there.

I've got some data currently stored in an Excel table, or a notepad
file depending on which would be easier to work with.. Im assuming
notepad(.txt) so that data can be read into php.

Anyway, this data is majorly corrupted and contains stuff i dont need.
For instance, a sample line is:

MNs73dd78INFORMATION I NEED 32427 12759 39384425 495242 15.206412
0.191214 44.164503 -93.993798

As you can see, its pretty messed up. I only need the "INFORMATION I
NEED" part, not the 9 characters before, nor any numbers or decimal
places afterwards.

I cant do this manually, as there are tens of thounsands of records.

Any ideas how I could go about this please.

Im assuming I would some how remove the first 9 characters, and then
some how remove all numbers and decimal places, but i've got no idea
how to go about it.

Kind Regards
Open the file
Loop through each line with fgets [1]
Use substr [2] to yank out from character 9 to whatever you need
Dump data into an array or an output file as you see fit

Now, if the data in each line you need is variable length (you don't
say), then it becomes trickier. You may have to tokenize the line with
something like explode [3], then do some logic to get only the tokens
you want. Or you may be able to figure out a regular expression to
trim off the data to the right (I'll leave that to someone much wiser
than I). There has to be some kind of standard format to the file
which delimits each field (either that, or whoever set up this file
royally screwed up).

[1] - http://us3.php.net/manual/en/function.fgets.php
[2] - http://us3.php.net/manual/en/function.substr.php
[3] - http://us3.php.net/manual/en/function.explode.php

Nov 15 '06 #2
Moot wrote:
Advo wrote:
>For instance, a sample line is:

MNs73dd78INFORMATION I NEED 32427 12759 39384425 495242 15.206412
0.191214 44.164503 -93.993798

Im assuming I would some how remove the first 9 characters, and then
some how remove all numbers and decimal places, but i've got no idea
how to go about it.

Kind Regards

Open the file
Loop through each line with fgets [1]
Use substr [2] to yank out from character 9 to whatever you need
Dump data into an array or an output file as you see fit
That's one way - but using RegEx would probably be
better... if you can figure out a *pattern* in the
corruption (e.g. first 9 characters, all numerals
after the last alpha character).

If you can't figure out a forumla/pattern - you'll
just have to do it manually. - no way around it.
Nov 15 '06 #3
Advo wrote:
>
MNs73dd78INFORMATION I NEED 32427 12759 39384425 495242 15.206412
0.191214 44.164503 -93.993798

As you can see, its pretty messed up. I only need the "INFORMATION I
NEED" part, not the 9 characters before, nor any numbers or decimal
places afterwards.
You can use regex maybe like this (not tested yet):

<?php

$fr = fopen ("data.txt", "r");
$fw = fopen ("data_clean.txt", "a");

while (!feof($fr))
{
$ln = fgets($fr, 1024);
$ln = preg_replace ("/^(\w{9})(.*)(\d+)/", "$2", $ln);
fwrite($fw, $ln);
}
fclose($fr);
fclose($fw);

?>

--
http://www.mastervb.net
http://www.theaussiemap.com

Nov 16 '06 #4
Or you could do something like:

$matches = array();
$fileText = file_get_contents('data.txt'); // PHP4.3+
if (preg_match_all ('/^.{9}(SUBPATTERN_THAT_MATCHES_YOUR_DATA).*$/m',
$fileText, $matches)) {
// $matches now contains your data, in this format:
// $matches[0][0] - the whole first matched line
// $matches[0][1] - your data from the first matched line
// $matches[1][0] - the whole second matched line
// $matches[1][1] - your data from the second matched line
// ... and so on.
} else {
// Your search failed - nothing matched.
}

Note that you'll have to replace SUBPATTERN_THAT_MATCHES_YOUR_DATA with
a valid regular expression describing the data you'd like to extract.

lorento wrote:
Advo wrote:

MNs73dd78INFORMATION I NEED 32427 12759 39384425 495242 15.206412
0.191214 44.164503 -93.993798

As you can see, its pretty messed up. I only need the "INFORMATION I
NEED" part, not the 9 characters before, nor any numbers or decimal
places afterwards.

You can use regex maybe like this (not tested yet):

<?php

$fr = fopen ("data.txt", "r");
$fw = fopen ("data_clean.txt", "a");

while (!feof($fr))
{
$ln = fgets($fr, 1024);
$ln = preg_replace ("/^(\w{9})(.*)(\d+)/", "$2", $ln);
fwrite($fw, $ln);
}
fclose($fr);
fclose($fw);

?>

--
http://www.mastervb.net
http://www.theaussiemap.com
Nov 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: lawrence | last post by:
If you're doing extensive formatting of output from a database, then you can't ask for all of a type of entry ("SELECT * FROM mainContent") and print it to the screen. On the one hand, it is an...
3
by: Paul Fairless | last post by:
Customers table - contains Columns: CustID, Surname, Forename, TtlID Titles table - contains Columns: TtlID, Title TtlID is a Foreign Key in the Customers table. I have a Form frmCustomers...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
7
by: Karin Jensen | last post by:
Hi I am running a PHP program that connects to an Access 2000 database via ODBC: $results = odbc_exec($connection_id, $sql_select); Is it possible to sort the contents of $results? I wish to...
5
by: Julia Baresch | last post by:
Hi everyone, I haven't found any reference to this problem on this group or in Access 97 help. I hope someone here knows this - probably a simple thing, but not obvious. I designed a query to...
10
by: Sjaakie | last post by:
Hi, I'm, what it turns out to be, fooling around with 3-tier design. At several websites people get really enthusiastic about using custom dataobjects instead of datasets/-tables. While trying to...
1
by: Nick Craig-Wood | last post by:
I've been dumping a database in a python code format (for use with Python on S60 mobile phone actually) and I've noticed that it uses absolutely tons of memory as compared to how much the data...
7
by: abracadabra | last post by:
I am reading an old book - Programming Pearls 2nd edition recently. It says, "Even though the general C++ program uses 50 times the memory and CPU time of the specialized C program, it requires...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.