1

I am attempting a PowerShell exercise but am currently stuck and could use some help.

I am looking to produce a script that can take two tab delimited input files(datafile1.txt, datafile2.txt) and combine them into a single tab delimited txt file.

-- datafile1.txt contains the following columns:

  • fielda(username)
  • fieldb(date)

-- datafile2.txt contains the following columns:

  • fielda(username)
  • fieldc(email)
  • fieldd(office)

This is what I have and I am able to output each file separately and even select just the start date from datafile1. But I can't figure out how to combine the two outputs into a single tab delimited text file. I feel like I'm so close but I'm too much of a pleb in my current state and about to pull my hair out. Thank you for any help provided.

I would like a single tab delimited text file that contains the following columns fielda, fieldc, fieldb and fieldd

$columnNamesFile1 = "username", "Date"

$oldFile = Import-Csv "C:\Users\username\Downloads\New folder\datafile01.txt" -Delimiter "`t" -Header $columnNamesFile1 |
    select "Start Date"
#$oldFile

$columnNamesFile2 = "username", "Email", "Office"

$datafile = Import-Csv "C:\Users\username\Downloads\New folder\datafile02.txt" -Delimiter "`t" -Header $columnNamesFile2 |
    select "ID", "Email", "Office"
#$oldFile2

Everything I've tried prints the date at the bottom instead of creating a new column with the date in it.

JosefZ
  • 28,460
  • 5
  • 44
  • 83

1 Answers1

0

what you're doing is joining two datasets on a column (username).

See if this helps: https://github.com/EliteLoser/MergeCsv

Install-Module -Name MergeCsv -Scope CurrentUser
Merge-Csv -Identity username -Path $file1,$file2 -Delimiter "`t"| Format-Table -AutoSize
Ambrose Leung
  • 3,704
  • 2
  • 25
  • 36
  • TY for your response. I think you understand what I am asking but unfortunately I am not allowed to install any CMDlets, can only use what Powershell comes with. – CuriousCoder Dec 30 '22 at 21:59