LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-02-2003, 04:25 PM   #1
spyghost
Member
 
Registered: Jun 2003
Distribution: Redhat
Posts: 245

Rep: Reputation: 30
loading from text file using column width


hi,

is it possible to place data according to the column width?

this is because some of the data that i need to place are strings that have spaces in between. also, some data are not "really" separated by anything! they are placed exactly adjacent to each other...

is there a way to do it in MySQL?

thanks...
 
Old 11-02-2003, 04:28 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
You will need to do it in what ever language you are programming in - you can do it by returning the relevant substrings then remove trailing spaces.
 
Old 11-02-2003, 04:38 PM   #3
spyghost
Member
 
Registered: Jun 2003
Distribution: Redhat
Posts: 245

Original Poster
Rep: Reputation: 30
please eleborate, i am new to databases... i don't get it...
 
Old 11-02-2003, 04:42 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
It really doesn't have anything to do with databases - you are just manipulating a text string. To give examples we need to know the language you are using and a few example records.
 
Old 11-02-2003, 05:17 PM   #5
spyghost
Member
 
Registered: Jun 2003
Distribution: Redhat
Posts: 245

Original Poster
Rep: Reputation: 30
ok, to start with, what i am doing is a web-based database running under rh 9.0, apache web server, mysql, and php.

here is a sample from the text file that i must load into the database prior to querying

03/09/00 08:01:58 Tayabas TAYABAS RTU Addr: 0x30 Acquisition Module Failed
03/09/00 08:02:00 Gateway GATEWAY RTU Addr: 0x26 Acquisition Module Ok
03/09/00 08:02:02 San Pablo 2 S3 CONCENTRATOR Addr: 0x20 Acquisition Module Ok
03/09/00 08:02:04 San Pablo 2 S3 CONCENTRATOR Addr: 0x31 Acquisition Module Ok
03/09/00 08:02:05 San Pablo 2 S3 CONCENTRATOR Addr: 0x22 Acquisition Module Ok
03/09/00 08:02:10 Gateway GATEWAY RTU Addr: 0x26 Acquisition Module Failed
03/09/00 08:02:17 Tayabas TAYABAS RTU Addr: 0x30 Acquisition Module Ok

here are the fields for this text file:
  • date
  • time
  • location - tayabas, gateway, san pablo 2
  • source - tayabas rtu, gateway rtu, s3 concentrator
  • address - addr: 0x?? acquisition
  • device - module
  • Message Text - ok, failed
 
Old 11-03-2003, 01:34 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Well I'll assume for the case of the example that the data is in a file called "data.in". Thihs example will just print the data out in a different format but you can use it to put the data into a database if you want:
Code:
<?php

$lines = file("data.in");

foreach ($lines as $line) {
$date = substr($line, 0, 8);
$time = substr($line, 9, 8);
$loca = substr($line, 18, 12);
$sour = substr($line, 31, 15);
$addr = substr($line, 56, 4);
$devi = substr($line, 74, 7);
$mess = substr($line, 82, -1);

print "$date - $time<BR>
Location: $loca<BR>
Source: $sour<BR>
Address: $addr<BR>
Device: $devi<BR>
Message: $mess<BR><BR>";
}

?>
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading a text file into a GtkTextView fails g_utf8_validate() MicahCarrick Programming 2 09-20-2005 09:58 PM
column width for netstat,top,etc minm Linux - Newbie 4 12-06-2004 01:30 AM
Konqueror - disable column width auto resize nnsg Linux - Software 0 09-05-2004 01:51 AM
Set text (runlevel 3) console character width davee Linux - Newbie 2 11-16-2003 03:33 PM
Changing Text Size/Terminal Width in Bash TastyWheat Linux - General 2 11-02-2003 11:24 PM


All times are GMT -5. The time now is 07:27 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration