0

The current script :

$csv = Import-Csv .\test1.csv -Delimiter ';'

$ref = @($csv.Column1)
foreach ($row in $csv) {
  foreach ($col in 'Column2', 'Column3', 'Column4') {
    if ($ref -contains $row.$col) { $row.$col = '' }
  }
}

$csv | Select-Object Column1,Column2,Column3,Column4

The current result:

Column1  Column2   Column3   Column4
-------  -------   -------   -------
infra-1  infra-852           infra-99
infra-98 infra-85  infra-44  infra-23
infra-5  infra-8             infra-10
infra-2  infra-55  infra-8   infra-70
infra-62           infra-852

CSV File:

Column1    Column2      Column3     Column4
infra-1    infra-852    infra-2     infra-99
infra-98   infra-85     infra-44    infra-23
infra-5    infra-8      infra-1     infra-10
infra-2    infra-55     infra-8     infra-70
infra-62   infra-5      infra-852   infra-5

This is what I want, example with Column1 as reference

Then Column2 in the same output

Column1   Column2   Column3   Column4
-------   -------   -------   -------
infra-98 infra-852 infra-44  infra-99
infra-62 infra-85  infra-8   infra-23
         infra-8   infra-852 infra-10
         infra-55            infra-70
                          
 
Column1   Column2    Column3    Column4
-------   -------    -------    -------
infra-1   infra-85   infra-2     infra-99
infra-98  infra-55   infra-44    infra-23
infra-2              infra-1     infra-10
infra-62                         infra-70
                           

To be short I want to have four columns with only the cells not matching with the reference column. The values of the column reference must diseppear with the values that match with it. This question is about making many arrays the other question is about just about excluding the empty cells.

Community
  • 1
  • 1
charlo
  • 121
  • 2
  • 3
  • 12
  • 1
    Your demand from the latter complex sentence is a bit incomprehensible (for me). Please [edit] the question and provide desired output satisfying rules of [mcve]. Maybe [Add Column to CSV Windows PowerShell](https://stackoverflow.com/q/17022017/3439404) could help? – JosefZ Jun 21 '17 at 08:10
  • I try to be, sry. – charlo Jun 21 '17 at 08:15
  • 1
    Your question is even less comprehensible now. Your last output sample is just your first output sample (that you said you don't want) times two. Please update your question with an example of the output you actually want. – Ansgar Wiechers Jun 21 '17 at 08:32
  • I think it's the best I can do here. – charlo Jun 21 '17 at 11:32
  • If I try with another foreach it remove the Column1. – charlo Jun 21 '17 at 14:02
  • What you want is going to really complex, because you aren't treating your csv like a PowerShell object. With `Import-CSV` each line of the CSV is an individual object with properties of each header. In your question, each column is an array. What you want is doable, but would be complex because that's not how psobjects work. – BenH Jun 21 '17 at 16:31
  • Is it possible to get this result by another way ? I can also make it with a XLSX if needed. – charlo Jun 22 '17 at 06:21
  • Possible duplicate of [Exclude cells which aren't displayed with Powershell](https://stackoverflow.com/questions/44647166/exclude-cells-which-arent-displayed-with-powershell) – G42 Jun 22 '17 at 08:27
  • This is differrent I wanted exclude the empty cells in the table here i want to get many table in the ouput – charlo Jun 22 '17 at 09:02

0 Answers0