Re: Reading Data Table
- To: mathgroup at smc.vnet.net
- Subject: [mg119945] Re: Reading Data Table
- From: "McHale, Paul" <Paul.McHale at excelitas.com>
- Date: Thu, 30 Jun 2011 20:41:07 -0400 (EDT)
- References: <201106301030.GAA15503@smc.vnet.net>
One quick way to do it is to read it in as a string and then use ImportString [] to sort it out. TestA.Txt: 1 2 3 4 5 6 In= mList=Import["c:\\testa.txt"]; In= mList=ImportString[mList,"Table"] Out= {{1,2,3},{4,5,6}} OR In= ReadList["C:\\testa.txt", Number, RecordLists -> True, WordSeparators-> {" ", "\[Backslash]t"}, RecordSeparators -> {"\r\n", "\n", "\r"}] Out= {{1,2,3},{4,5,6}} Note: Don't leave Number specifier out! Also, here is the URL in the help system that I used (if it helps): tutorial/ReadingTextualData Type that into the search box in the help system. Paul McHale | Electrical Engineer, Energetics Systems | Excelitas Technologies Corp. Phone: +1 937.865.3004 | Fax: +1 937.865.5170 | Mobile: +1 937.371.2828 1100 Vanguard Blvd, Miamisburg, Ohio 45342-0312 USA Paul.McHale at Excelitas.com www.excelitas.com Please consider the environment before printing this e-mail. This email message and any attachments are confidential and proprietary to Excelitas Technologies Corp. If you are not the intended recipient of this message, please inform the sender by replying to this email or sending a message to the sender and destroy the message and any attachments. Thank you -----Original Message----- From: fractal11 [mailto:trchan at mit.edu] Sent: Thursday, June 30, 2011 6:31 AM To: mathgroup at smc.vnet.net Subject: [mg119945] Reading Data Table Is there a way to read a file with a user specified word separator and record separator, such that the result is a list of lists of words? For example, a file containing "1 2 3\n4 5 6" would become {{1,2,3}, {4,5,6}}. Import does almost exactly what I want, although I can't figure out how to change the word and record separators. In particular, I have a file where word separators are tab characters, but the data themselves have spaces. Therefore, Mathematica's default word separator of whitespace does not work.
- References:
- Reading Data Table
- From: fractal11 <trchan@mit.edu>
- Reading Data Table