Current location: Hot Scripts Forums » Programming Languages » Perl » [SOLVED] Converting Columns into New Text Files


[SOLVED] Converting Columns into New Text Files

Reply
  #1 (permalink)  
Old 11-28-07, 06:45 PM
engIntern engIntern is offline
Newbie Coder
 
Join Date: Nov 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Converting Columns into New Text Files

I have a question with regard to converting text columns into new text files.
For example, say that I have the following text file. The information is in hex.
There are no headings or subheadings of any type. Just the raw data in column format. Each column is its own data set. How do you convert each column into its own text file so that I will have 100 text files created for every column?

A3 4B 34 . . . 100th
. . . .


. . . .

. . . .

5C 11 CB. . . 100row

Please, any help would be greatly appreciated.

Last edited by engIntern; 11-28-07 at 06:47 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-28-07, 09:00 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
In this little program "yourfile.txt" should be replaced by the name of your text file.

And the name of the files that will be created are called "file" plus a number, starting at o plus the extention ".txt".

ie: file0.txt, file1.txt, file2.txt, etc...

You can change the text values "file" & ".txt" to what ever you want.
Provided you follow the rules for naming files.

PHP Code:

<?php
$temp 
explode("\r\n",file_get_contents("yourfile.txt")); // Get the rows of data from the text file and put them in an array.
for($i=0;$i<count($temp)-1;$i++){$temp1[$i] = explode(" ",$temp[$i]);} // This loop converts the $temp array into a two-dimentsional array (rows&columns).
for($c=0;$c<count($temp1[0]);$c++) // This double loop converts the columns of the two-dimentsional array into string variables and writes the variables to files.
{
 for(
$r=0;$r<count($temp1);$r++){${"file".$c} .= $temp1[$r][$c]." ";}
 
$fn fopen("file".$c.".txt","w");
 
fwrite($fn,${"file".$c});
 
fclose($fn);
 }
?>
__________________
Jerry Broughton

Last edited by job0107; 11-28-07 at 09:12 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-30-07, 12:14 PM
engIntern engIntern is offline
Newbie Coder
 
Join Date: Nov 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Spin Thank You job0107

Hi job0107,

thank you for your help on this problem. What would we hardware guys (analog/RF) be without the support of our fellow software compatriots. Thank you so much for your help on this one.

It appears that this Perl is very useful. I have never programmed in Perl before. I have only taken the required C/Assembly undergrad software courses in college. Once I finish school, I will definitely take programming classes exclusively. It appears that it is a must for any engineer nowadays.

Again, I thank you for your generous help job0107.

Sincerely,

engIntern
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 12-01-07, 06:12 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Your welcome.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search script improvement 9999 PHP 14 08-29-06 12:46 AM
Draggable Tables Ares JavaScript 10 08-03-06 07:55 AM
Need Your HelP! Loading Multiple External Text into Multiple Dynamic Text Fields Flash_Boi Flash & ActionScript 2 03-30-06 04:27 PM
CMS using text files. May use Flash as the interface. bchalker Script Requests 0 02-06-04 02:47 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 08:19 PM


All times are GMT -5. The time now is 01:36 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.