0

The following script can select two columns from CSV files with headers.

import-csv file1 | select x,y 

However, how to select column by index, for example column 9 and 10, from csv file without header?

import-csv file2 | select 9?,10? 
ca9163d9
  • 27,283
  • 64
  • 210
  • 413
  • 1
    possible duplicate of [How to extract one specific column (no header, say column 2) from multiple csv files using Powershell?](http://stackoverflow.com/questions/28776973/how-to-extract-one-specific-column-no-header-say-column-2-from-multiple-csv-f). This answer specifically: http://stackoverflow.com/a/28777087/3829407 – Matt Jun 23 '15 at 19:39

1 Answers1

5

So Import-CSV isn't going to like a file with no headers, it will assume that your first record is the header unless you specify one. At that point you'll just assign headers to the columns, and you can reference those...

import-csv file2 -header Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12 | Select Col9,Col10
TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56