# specifying range of rows and columns of importing data

I have a text file that has below general form:

name of file
dataname1
value1 data data data data
value2 data data data data
value2 data data data data
dataname2
value2 data data data data
value2 data data data data
value2 data data data data


I want to import the file and extract just "data" from it. Namely in this example I need to select the rows 4-6 and 8-10 and then columns 2-5. How can I write such code? This code gives me just one set of specific rows,

Import["name.txt", {"Data", Range[4, 6]}]


but I don't know how to specify columns. Note that all information are separated by one space. Thanks in Advance.

• Try Part[ Import[ "name.txt", "Table"] , {4, 5, 6, 8, 9, 10}, 2 ;; 5] – Jason B. Mar 26 '18 at 16:08
• You'll also want to look up the HeaderLines option to strip out the headings at the beginning. – J. M. will be back soon Mar 26 '18 at 16:10
• @JasonB. Thanks a lot. I try this Jason Part[Import["name.txt", "Table"], Range[14, 29], 2 ;; 6] for my original file and it worked. is there a general command for specifying rows and columns of a imported file in Mathematica? – Wisdom Mar 27 '18 at 5:53
• @ J. M. needs help. Thanks – Wisdom Mar 27 '18 at 6:40
• @NSR in general you were on the right track.. Import["name.txt", {"Table", "Data", Join[Range[4, 6], Range[8,10]], Range[2, 5]}] works.. The general form for import of 2d data is {format, element, rows, columns}, so to just take columns it would be {"Table", "Data", All, Range[2,5]}. For "Table" only Ranges will work, but for CSV and XLSX spans will work as well in 11.3.. We're working on updating these even more, and hope Table will be updated also in the future. – GenericAccountName Jun 28 '18 at 15:01