Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7029829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:35:23+00:00 2026-05-28T00:35:23+00:00

I am having a file where component Baseline and component names where stored as

  • 0

I am having a file where component Baseline and component names where stored as follows

(Mailcomp@\My_PVOB) BL_2.1.0.9.5179@\My_PVOB
(OfficeComp@\My_PVOB) BL_2.1.0.17.6972@\MY_PVOB

Actually i need to Construct a hash table which may have entries like

@(Key=Mailcomp,Value=BL_2.1.0.9.5179)
@(Key=OfficeComp, Value=BL_2.1.0.17.6972)

I was trying to replace like follows

(Get-Content $BaselineFile) | foreach{ $_ -replace "@\My_PVOB[?]",''} | Out-File  $BaselineFile

Then i tried to Create hash table , but the first command itself failed and i don’t know how to create hash table from file entries. Can some one help me please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:35:23+00:00Added an answer on May 28, 2026 at 12:35 am

    At the time of writing there are two answers (one from Shay Levy and one from jon Z) that are both close, but neither is quite right–despite the fact that Shay’s answer has already been accepted (!). Here’s why:

    Issues with Shay’s code

    Shay’s answer is too literal, based on an inaccurately stated requirement that specifies creating a “hash table which may have entries like” this:

    @(Key=Mailcomp,Value=BL_2.1.0.9.5179)
    @(Key=OfficeComp, Value=BL_2.1.0.17.6972)
    

    But if one is going to use PowerShell syntax, that is stated incorrectly. The requirement in reality should look like this:

    @{Mailcomp=BL_2.1.0.9.5179}
    @{OfficeComp=BL_2.1.0.17.6972}
    

    That is to say, the first line specifies a hash key of Mailcomp and a hash value of BL_2.1.0.9.5179. This modified version of Shay’s code delivers precisely that:

    $hash = @{}
    Get-Content $BaselineFile | 
    Foreach-Object {
        if ($_ -match '^\(([^@]+).+\)\s([^@]+)')
        {
            $hash[$matches[1]]=$matches[2]
        }
    }
    

    Here’s the output:

    Name       Value
    ----       -----
    Mailcomp   BL_2.1.0.9.5179
    OfficeComp BL_2.1.0.17.6972
    

    This is much easier to work with, as I can now access $hash["Mailcomp"] or $hash["OfficeComp"] to retrieve their respective values.

    A second problem with Shay’s code is the hash entry creation itself (@{ key=$matches[1]; value=$matches[2] }). That statement creates a separate “mini” hashtable for each iteration (i.e. each line of the input). It only seems to produce reasonable output because of the amalgamation of the implicit Write-Output in his code. To prove this–and to compare apples to apples–take my code above and replace the conditional with this equivalent to Shay’s code:

        if ($_ -match '^\(([^@]+).+\)\s([^@]+)')
        {
            @{ $matches[1]=$matches[2] }
        }
    

    You will find that $hash["Mailcomp"] does not return the expected BL_2.1.0.9.5179.

    Issues with Jon’s code

    I like jon Z’s answer; I really do. Really. But it reminds me of the great old joke with the punchline assume we have a can opener… It is a very good solution if and only if the input is amenable to a simple delimiter. Not the case here–a regular expression (or other mechanism) is required to massage the input. In all fairness, Jon notes that explicitly by stating he is assuming some preprocessing. `Nuff said.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having XML like as follows <Components> <Component> <Name>Comp1</Name> <Baseline>Comp1_2.1.0.20.2824</Baseline> <KLOC>0</KLOC> <IsCount>True</IsCount> </Component>
I have a File having text and few numbers.I just want to extract numbers
In a way following on from reading a windows *.dmp file Having received a
I'm using VS2010 Ultimate. Having code: //file IntSet.h #include stdafx.h #pragma once /*Class representing
Am having a batch file used to update certain files. However when i try
I am having a php file which executes some code to generate a html
How do I invoke an EXE from a batch file without having the latter
Is there any way to print an OOXML document (.docx file) without having MS
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
Im having trouble reading from a CSV file final String DELIMITER = ,; Scanner

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.