File with irregular spaces and tabs split/explode columnwise

So I have a very old file with thousands of lines (I guess generated by hand) and I'm trying to move them into a rdb, but the lines don't have a format/pattern to convert into columns. Say for example the lines in the file looks like:

blah   blahsdfas    laslkdlasdj      aksdjla
sldks  slslsl      lsdlksldj           lsdjlfslk

I could say it has four fields when I look at it, primarily tried using awk but it wasn't printing the column as expected because the space between a column is not tab or with an equal space count.

You guys think its possible to extract? If yes can someone help with a php snippet?

Answers


Using preg_split(), you can break the line up using one or more whitespace characters as the delimiters:

$lines = file('filename', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($lines as $line)
{
    $pieces = preg_split('/\s+/', $line);
    // do something with pieces
}

Need Your Help

Garbage collection in Backbone

javascript backbone.js memory-leaks marionette garbage

* Updated - Added a sample code for one of the view *

How to tint a Bitmap to a solid color

android colors tint

How would one go about tinting a Bitmap to a solid color, effectively replacing all pixels that have an alpha > 0 to a given RGB value? In addition how to do the same thing, but keeping the alpha for