1

I'm trying to get from this file ->

File 1:

Name;Datum;Nominal;L_TOL;U_TOL;Value;Unit;Feature;low nat. Border;Type;No.;Date;Time;Operator

abstrich_;;   0.00;   0.00;   0.00;   0.02;mm;0;0;9315;1;16.03.23;14:59:02;xy
abstrich__;;   0.0;   0.0;   0.0;   0.2;mm;0;0;9315;2;16.03.23;14:59:02;xy
mp_658__;;   0.000;   0.000;   0.480;   0.164;µm;0;2;100;3;16.03.23;14:59:02;xy
rough01_Pt;;   0.000;   0.000;   0.810;   0.389;µm;0;2;9350;4;16.03.23;14:59:02;xy
rough02_Rz;;   0.000;   0.000;   0.500;   0.264;µm;0;2;9350;5;16.03.23;14:59:02;xy

to this format ->

File 2:

abstrich_;0.02
abstrich__;0.2
mp_658__;0.164
rough01_Pt;0.389
rough02_Rz;0.264

I don't know how to extract these two values and merge in one line.

I need a solution with Import-Csv which let me bring the first file in the second format.

Piravienth
  • 21
  • 2
  • Where are your attempts? You need to show what you've tried. – Destroy666 Mar 23 '23 at 09:48
  • Use Export-CSV and specify only the columns you need : https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-csv?view=powershell-7.3 – jdweng Mar 23 '23 at 10:01
  • 2
    `Import-Csv -Delimiter ";" -Path "source_path" | Select Name,Value | Export-Csv -Path "target_path"` – Avshalom Mar 23 '23 at 10:02
  • Using this [`Join-Object script`](https://www.powershellgallery.com/packages/Join)/[`Join-Object Module`](https://www.powershellgallery.com/packages/JoinModule) (see also: [In Powershell, what's the best way to join two tables into one?](https://stackoverflow.com/a/45483110/1701026)): `Import-Csv .\File1.Csv -Delimiter ';' |Update-Object (Import-Csv .\File2.Csv -Delimiter ';' -Header Name,Datum) -on name |Export-Csv .\Output.Csv` – iRon Mar 23 '23 at 10:38

1 Answers1

2

This command does output the specified data to file if you want headers:

Import-Csv -Path "test.csv" -Delimiter ";" | Select Name,Value | Export-Csv -Path "test2.csv"

You import the CSV to an object list, then select only specified properties and save them to another CSV.

And this one can be used if you want no headers as in example:

(Import-Csv -Path "test.csv" -Delimiter ";" | Select Name,Value | ConvertTo-Csv -NoTypeInformation) | Select -Skip 1 | Set-Content -Path "test2.csv"

Here you again import the CSV and select only specified properties, then you need a workaround of converting to CSV format and skipping the 1st row of the full content. And you output the resulting content as CSV.

Destroy666
  • 892
  • 12
  • 19