From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to read columns from text file and save in another text file

Hi i m new user of labwindows. i want to read columns from text file and then save some columns in another file. for example a text file with 11 columns are

a b c d e f g h i j k

1 2 3 4 5 6 7 8 9 8 2

so i have 11 columns and 11 rows. now i just want to read columns from text file and then want to save two columns in someother file. for example column 4 and 5. kindly brief me in detail

 

0 Kudos
Message 1 of 8
(4,970 Views)

kindly rply me soon i m waiting for ur replys

0 Kudos
Message 2 of 8
(4,937 Views)

Given that there is not a unique command that does what you want, you can build up you solution splitting it into two tasks:

-read data from file

-extract data and save to a new file

 

Each task can be solutioned in more ways: as a general suggestion you can use FileToArray to read the file and get your data.

You can then use functions from Formatting and I/O Library to save data to a new file.

 

As an alternative consider using File I/O for the first task also:  Open file,  Read Line (as I understand you have a text file that can be read line by line) to read the file; Scan to extract only the columns you want from the line.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 8
(4,906 Views)

sir Roberto thnx for your reply sir i still cant understad how to solve my problem i m attaching text file for an example kindly give me the code how to extract 3rd and 5th column from that file and saving another file. i shall be very thankfull to u sir. i never work before that on labwindows so initialy help me in more detail plz.

0 Kudos
Message 4 of 8
(4,823 Views)

sir Roberto i i read the file the will be stored in a single array as a whole then how can i split the particular column and save it into the new file. i m confuse sir kindly help me i saw that u r a supporting guy to all people i love programing i will work hard but in start i need great help sir

 

0 Kudos
Message 5 of 8
(4,821 Views)

Unfortunately I am on vacations now with no PC so I can only give you some conceptual framework for you to elaborate on. The help for the commands I list will be helpful; I suggest you also look in the  examples supplied (search by help 》find examples function) and/or look in the forums.

 

The framework you can start with is the following: not the most efficient but simple an fast enough for small files (say < 1 Mb).

 

OpenFile (source file, Read only)
OpenFile (destination file, write only)

Read one line from source if you have heading row
Create proper line in destination if you want heading row

while (1) {
  r = ReadLine  (source file, put into a buffer)
  Test 'r' for end-of-file condition: break out the loop

  Scan (buffer, look in command help to skip unwanted fields and extract only desired ones)
  e.g. Scan (buffer, "%2d[d]%d%d[d]%d", &var1,  &var2) will extract 3rd and 5th field

  sprintf (create the output string in the format you want
  WriteLine (destination file)
}
CloseFile (source)
CloseFile (destination) 

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 8
(4,738 Views)

sir kindly explain me scan function in detail i m also confused in using that function

0 Kudos
Message 7 of 8
(4,705 Views)

The best I can offer you at present is the help on the function, which includes several examples on how to use it in various scenarios.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 8
(4,696 Views)