-5

Source file looks like:

Pre-delivery;1234567
Post-delivery;7654321

Lookup file:

1234567;A
7654321;B

Output should be:

Pre-delivery;A
Post-delivery;B
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Sheldon
  • 11
  • 5
  • 1
    very easy with a replace... what have you tried so far? – T-Me Jan 08 '19 at 08:28
  • 1
    I didn't know SO is now a place to have others get your work done. – marsze Jan 08 '19 at 08:30
  • I'm new. I've researched about hash table but i do not know the right syntax after that – Sheldon Jan 08 '19 at 08:30
  • 2
    Don't worry too much about the snappy comments. Anyway, a question is expected to follow a certain [set of standards](https://stackoverflow.com/help/how-to-ask). For starters, edit it and include details what you have managed to do and what is still unclear. Can you read and write files? Is hashtable population a problem or content replacing? – vonPryz Jan 08 '19 at 08:36
  • apologies for asking here at SO. Don't worry, I'm also doing my research via Google in parallel while waiting answers from here. anyway thanks for comments – Sheldon Jan 08 '19 at 08:40
  • 1
    No need to apologize about asking. Instead, edit the question and add more details. For example, if you already know how to read files, there's no need to explain that in an answer. I've whipped up a quick solution, but it's unlikely to fit your particular case. – vonPryz Jan 08 '19 at 08:55
  • awk 'FNR==NR{a[$2]=$1;next}{print a[$2],$2}' Test1.txt Test2.txt | column -t Error: awk : The term 'awk' is not recognized as the name of a cmdlet, function, – Sheldon Jan 08 '19 at 09:05
  • 2
    AWK is not PowerShell.. – Theo Jan 08 '19 at 11:03
  • 1
    Please do not post information that is relevant to your question as comments. [Edit] your question instead. – Ansgar Wiechers Jan 08 '19 at 11:34

1 Answers1

0

Done in 10 minutes ..

Not well optimized solution

  • its reading the whole file for every row which is found in lookup file
#https://stackoverflow.com/questions/54087831/lookup-on-file-and-output
#inspired by https://stackoverflow.com/questions/33511772/read-file-line-by-line-in-powershell 

<#
source file 
    Pre-delivery;1234567
    Post-delivery;7654321

lookup file
    1234567;A
    7654321;B

result
    Pre-delivery;A
    Post-delivery;B
#>

$sourceFile=".\foosource.txt"
$lookup=".\foolookup.txt"

# read lookup file line by line
foreach($lineLookup in Get-Content $lookup) {

    #read source data file line per line
    foreach($line in Get-Content $sourceFile) {
    #prepare variables
     $splitLookup=$lineLookup.Split(";")
     $splitSource=$line.Split(";")

     #if equals
     if($splitLookup[0] -eq $splitSource[1]){
        #print in the given format
        $result = $splitSource[0].Trim()+";"+$splitLookup[1].Trim()
        Write-Host $result
     }

    }

}
xxxvodnikxxx
  • 1,270
  • 2
  • 18
  • 37