Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing Multiple text files in one format & Exporting in another

Status
Not open for further replies.

akshaynr

Technical User
Sep 13, 2010
3
US
I have about 450 text files, all of which are in one single format. The first 3 lines contain information about the file and is not relevant. The 4th line is important and goes like this for example:
NPTS= 3200, DT= .00500 SEC

NPTS refers to the number of points in the file which are below this line. From the 5th line, the data points start. The data points are arranged in 5 columns. The order of the data points are from left to right, then next line left to right and so on till the end is reached. The data points are separated by a space. There are both +ve and -ve values. There are 3 spaces between the beginning of the line and the +ve number. There are 2 spaces between the beginning of the line and -ve numbers. (The '-' sign takes up that extra space) The same seperation applies to the space in between the columns. All numbers start with a decimal and are expressed in an exponent form. For example:
-.234234E-02 .32452342E-03 .8979873E-05 -.3248324E-02 .9879873E-01
I have replicated the spaces exactly as well. Here is what I need:

The text files are already named. I need a macro that will import these text files from a specified folder, convert them to a 2-column format in excel- 2 columns for every text file. Even if this means I am going to have some 900 columns, that is fine with me. The first column is going to be using the NPTS and the DT values. If the NPTS equals 3000 and DT= .05, then the first column will have values: 0,.05,.1,.15,.2,.25......150. Essentially it is n*DT from n=0 upto n=NPTS. The 2nd column is going to involve the 5-column data. I need all the data to be in one single column and corresponding to the values in the first column. After one file is done, go on to next file. The 2 columns from the next file can be placed right next to the previous file or with a column in between. I need the filename on top of the 1st or the 2nd column. On top of the 1st column, i need the value of NPTS and on top of the second column, the value of DT. For example, the excel workbook is going to look like this:

XYZ
3000 .05
0.0 23432
0.05 23432
0.1 35332
. .
. .
. .
150.0 90823

THIS IS ONLY THE HALFWAY MARK Unfortunately!
After this, I need the macro to export these 2 column data to separate text files in a 2 column format. The final text file will have the same filename as the initial one did. The first row of the final text file will have the value of NPTS, followed by a tab, and then the value of DT. It just requires the values and not the letters NPTS or DT. The second line onwards, the data needs to be arranged exactly as is given in the excel worksheet. The output text file will essentially be the same as the output i have shown above, except that the file is going to be named as indicated and the filename (XYZ) is not going to be shown in the data. The spacing between the two columns at any place is ONE TAB (+ve or -ve values). And all numbers should be in decimal.
I need separate text files for every two columns that were created while the data was imported in the manner explained. And all need to be exported to the same folder.

Appreciate any help I can receive in this regard. Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top