Currently the street address is added like: Street1 City1 so I want the City1 to appear on a new line.
Add line break import-csv
I want to create some new users and add street address which a multi-line string. I have a csv file with the user name and street address. I want that when I add the users the Street and City are added on the new line and not added on the same line. How can I achieve this?
Windows for business Windows Server User experience PowerShell
3 answers
Sort by: Most helpful
-
-
Rich Matheisen 47,901 Reputation points
2021-03-04T15:02:57.307+00:00 Something like this?
Import-Csv C:\junk\x2.txt | ForEach-Object{ $_.Address = $_.Address.Split(" ") -Join "`n" $_ } |Export-Csv C:\junk\x2.csv -NoTypeInformation
I have no idea what your real data look like so how you go about separating the street address from the city name is unknown.
-
Anonymous
2021-03-05T07:26:20.207+00:00 Hi,
Does this meet your needs?
$file = 'D:\temp\users.csv' $output = 'D:\temp\users2.csv' $address = @' {0} {1} '@ Import-Csv -Path $file | foreach-object { $street, $city = $_.address -split ' ' $_.address = $address -f $street, $city $_ } | Export-Csv -Path $result -NoTypeInformation
If the street address and city address also have spaces, you have to separate them with some other symbol instead of the space.
Best Regards,
Ian Xue============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.