Author Posts

August 10, 2015 at 2:32 pm

Need to split Database-A and 40005 from CELL A4 and need to place Database-A in Column A4 and need to replace 1414 with 40005 in Column B4. Could anyone helpme out on this?

URL Port
Application-a.com 1414
Application-b.com 1414
website-x.com 25025
website-y.com 20208
Database-A,40005 1414
Database-B,40000 1414

COLUMN A:
URL
Application-a.com
Application-b.com
website-x.com
website-y.com
Database-A,40005
Database-B,40000

COLUMN B:
Port
1414
1414
25025
20208
1414
1414

August 11, 2015 at 4:39 am

Saving your first example as Test.csv:

#Open CSV with space delimiter and write results to $results var
$results = Import-CSV C:\Temp\test.csv -Delimiter " " | 
foreach{ 
    #if the URL contains a comma
    if ($_.URL -like "*,*") {
        #Split and create and array at the comma
        $split = $_.URL -Split ","
        #Update the URL and port with the split data
        $_.URL = $Split[0]
        $_.Port = $Split[1]
    }
    $_
}

$results | Format-Table -AutoSize

Output:

URL               Port 
---               ---- 
Application-a.com 1414 
Application-b.com 1414 
website-x.com     25025
website-y.com     20208
Database-A        40005
Database-B        40000

August 11, 2015 at 1:34 pm

Hi Rob,

Thanks for your reply. I tried your logic but I am getting the ouput as you specied. I am getting the output like

URL,PORT
——–
Application-a.com,1414
Application-b.com,1414
website-x.com,25025
website-y.com,20208
Database-A,40005,1414
Database-B,40000,1414

August 11, 2015 at 5:53 pm

The example you posted was space delimited:

URL Port
 Application-a.com 1414
 Application-b.com 1414
 website-x.com 25025
 website-y.com 20208
 Database-A,40005 1414
 Database-B,40000 1414

If it is comma-delimited, you need to simply remove -Delimiter " "

August 18, 2015 at 9:13 am

Hi Rob,

Thanks it got resolved