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

Complex text file import problem

Hi,
I have a complex text file import issue.

The first 13 lines of the file need to be skipped.

Then each of the next 2 lines need to be combined in one record.
the format of one record should look something like this ..
index number / date / time / error code / error description

Help would be greatly appreciated.

g's Sam

Expand|Select|Wrap|Line Numbers
  1. ****************************************
  2. *                                      *
  3. *  C O M A U  :  Robotics              *
  4. *                                      *
  5. d*  C 3 G  :  3^ Generation Control     *
  6. *                                      *
  7. *       ERROR      LOG      FILE       *
  8. *                                      *
  9. ****************************************
  10. * ERROR FORMAT RELEASE     : 1.0       *
  11. * MAX REMEMBERED ERRORS    :  20       *
  12. * LATEST ERROR IN POSITION :   5       *
  13. * ERROR LINE LENGTH        :  80       *
  14. ****************************************
  15.  
  16.  
  17.  
  18. <001>    08-11-12 09:15:15
  19. 30777-10 : DP SL slave not ready                                                
  20. <002>    08-11-12 09:26:00
  21. 43276-04 : A_SW1B: $DIN[2]=OFF, micro not indicates "gun open"                  
  22. <003>    08-11-12 09:27:42
  23. 36912-04 : rsssssrr(34): unmatching FOR loop                                    
  24. <004>    08-11-12 09:55:29
  25. 62479-08 : SA: 1 1 wrist axis at undefined position                             
  26. <005>    08-11-12 10:09:29
  27. 62482-10 : SAX: 1 1 1 tolerance HOLD unobtainable                               
  28. <006>    08-11-12 06:17:39
  29. 28774-10 : Power failure detected                                               
  30. <007>    08-11-12 06:17:40
  31. 43274-04 : A_SW1B: MP 1 $DIN[35]=OFF, no air                                    
  32. <008>    08-11-12 06:17:49
  33. 30777-10 : DP SL slave not ready                                                
  34. <009>    08-11-12 06:19:47
  35. 43260-10 : Welding control switch 1 failure                                     
  36. <010>    08-11-12 06:25:07
  37. 43522-04 : HTChg: Tool on flange INP fault $DIN[ 16] = ON                       
  38. <011>    08-11-12 06:25:16
  39. 43522-04 : HTChg: Tool on flange INP fault $DIN[ 16] = ON                       
  40. <012>    08-11-12 06:25:27
  41. 43522-04 : HTChg: Tool on flange INP fault $DIN[ 16] = ON                       
  42. <013>    08-11-12 06:27:13
  43. 30777-10 : DP SL slave not ready                                                
  44. <014>    08-11-12 06:38:32
  45. 61442-11 : SAX: 1 1 2 following error out of range                              
  46. <015>    08-11-12 06:41:21
  47. 43274-04 : A_SW1B: MP 1 $DIN[35]=OFF, no air                                    
  48. <016>    08-11-12 06:41:21
  49. 43292-04 : A_SW1B: [02] Switch  1 $GIN[14] = 0. Welding control switch not open 
  50. <017>    08-11-12 06:46:26
  51. 28774-10 : Power failure detected                                               
  52. <018>    08-11-12 06:46:26
  53. 26636-10 : BS: (0,5) I/O module failed                                          
  54. <019>    08-11-12 06:46:36
  55. 30777-10 : DP SL slave not ready                                                
  56. <020>    08-11-12 06:46:55
  57. 43260-10 : Welding control switch 1 failure
Jun 24 '13 #1
2 1790
zmbd
5,501 Expert Mod 4TB
SDEBEUL
What have you tried so far?

We can help you with a specific snag in your code; however, we need something to work with first.

Also, the record you propose doesn't seem to follow the normalization rules: Database Normalization and Table Structures.
Jun 24 '13 #2
ADezii
8,834 Expert 8TB
Here is the Logic as I see it:
  1. Input each Line of the File into a Variable.
  2. Ignore the first 13 Lines of the File.
  3. Analyze each Line. If it is an Index Line, just remember it, but if it is not, build a String consisting of the Index Line, a Separator (|), and the next consecutive Line after the Index Line.
  4. Output each Line to an Output File.
  5. Loop through the entire File until the end is reached, using the same Logic for each Line.
    Expand|Select|Wrap|Line Numbers
    1. Dim intLineNum As Integer
    2. Dim strIndex As String
    3. Dim strBuild As String
    4.  
    5. Open "C:\Test\Input.txt" For Input As #1    'Input File
    6. Open "C:\Test\Output.txt" For Output As #2  'Output File
    7.  
    8. intLineNum = 0                              'Initialize
    9.  
    10. Do While Not EOF(1)                         'Loop until end of file.
    11.   intLineNum = intLineNum + 1               'Increment Line Number
    12.     Line Input #1, strLine                  'Input entire Line into a Variable
    13.       If intLineNum > 13 Then               'Skip the first thirteen Lines
    14.         If Left$(strLine, 1) = "<" Then     'Is it an Index Line, yes if '<'?
    15.           strIndex = strLine
    16.             strBuild = ""                   'Don't concatenate, Index Line
    17.         Else
    18.           'Build String, (Index Line & ' | ' & Line below)
    19.           strBuild = strIndex & " | " & strLine
    20.         End If
    21.           Print #2, strBuild
    22.       End If
    23. Loop
    24.  
    25. Close #1    'Close Input File
    26. Close #2    'Close Output File
  6. This Code does work with certain parameters, but it is only meant to be a general guildline for you to follow. Any other questions, please feel free to ask.
  7. Sample Output after executing Code, using limited Data:
    Expand|Select|Wrap|Line Numbers
    1. <001>    08-11-12 09:15:15 | 30777-10 : DP SL slave not ready                                                
    2. <002>    08-11-12 09:26:00 | 43276-04 : A_SW1B: $DIN[2]=OFF, micro not indicates "gun open"                  
    3. <003>    08-11-12 09:27:42 | 36912-04 : rsssssrr(34): unmatching FOR loop                                    
    4. <004>    08-11-12 09:55:29 | 62479-08 : SA: 1 1 wrist axis at undefined position 
Jun 25 '13 #3

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

Similar topics

2
by: Dave Stone | last post by:
Does anyone know if it's possible to use the wizard or DTS Designer to accept a source file with the following simplified format: <field1label>: <record1field1value> <field2label>: ...
5
by: Johnny Meredith | last post by:
I have seven huge fixed width text file that I need to import to Access. They contain headers, subtotals, etc. that are not needed. There is also some corrupt data that we know about and can...
2
by: Salad | last post by:
When I attempt to import/link a text file, I select the type of file as TextFiles, select the text file, and hit the Import or Link button. No specification file is presented and nothing gets...
7
by: Joe Fallon | last post by:
I am importing a delimited ASCII text file into a dataset using OLEDB. I set up the connection and dataadapter and then fill the dataset. It works - sort of. It turns out that some of my data is...
1
by: GB | last post by:
Hello: I need to import an Excel file to SQL Server. The .xls file has the column names which contains dot inside, like AAA.BBB. When I import this file in SQL using DTS Import/Export tool, it...
10
by: Avi | last post by:
Hi I need to read in a large set of text files (9GB+ each) into a database table based on fixed width lengths. There are several ways to complete this, but I am wondering if anyone has...
11
by: Someone | last post by:
Hello Using the c file io functions if reading a csv file there is a problem if a field contains an embedded carriage return. So I can check for apostrophe pairs but processing does seem a bit...
1
by: Child of His | last post by:
I have been through every trick I know, or has been suggested. I have a one to two million line fixed field database in text format. I want to bring it into Access 97. When I use the external...
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: 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
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
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.