get specific cell value in csv file using powershell

人走茶凉 提交于 2019-12-14 03:08:13

问题


I am new to powershell, don't get to use this often.
I need to output the value of cell A5 from a csv file using powershell

my file -

col1 col2 col3 col4
---- ---- ---- ----
1002 1005 1006 1007

need value in the A1 cell i.e 1002.selection should be done by the cell numbers.

$a = @(Import-CSV filepath.csv)
$a[1].(col1)

thanks in advance


回答1:


Import the CSV to your variable

$a = Import-CSV filepath.csv

Then grab the first row $a[0] and use . notation to get the column you want. Note that the first row of data is 0 because powershell converts the CSV to an object, seperating the headers and data.

$a[0].col1

If you don't need any other values from the CSV, then you can forego the variable assignment and trim it down to:

(Import-CSV filepath.csv)[0].col1



回答2:


Row 1, Column 1 (A1)

$a[0].psobject.properties.value[0]

Row 1, Column 5 (A5)

$a[0].psobject.properties.value[4]


来源:https://stackoverflow.com/questions/52433562/get-specific-cell-value-in-csv-file-using-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!