Make column and insert array contents inside the column.
I am reading in CSV file, after that I use -match to find a pattern I am looking for. I now have all of my matches inside a variable called $results. Next, I would like to create a new column and insert the contents of $results into that column. I have been stuck on this for a while, I have attempted to use for loops, forEach loops, if statements, and I cannot seem to get the results that I am looking for. I am new to Powershell, so I may be missing something obvious. Any help is greatly appreciated!
Here is my code:
$target = "This is the path to the .CSV file"
$pattern = '(V-d*)'
$TestFile = (Get-Content $target)
$results = $TestFile | Select-String $pattern -AllMatches
$results.Matches.Value
#$TestFile -replace '(V-d*)',' '
$NewFile = ConvertFrom-Csv $TestFile| Select-Object *,@{Name='Generic
Header';Expression={"Unsure of how to input data here without having all
data in same row"}}|export-csv ' Path for Exporting New .CSV file' -notype
powershell
|
show 3 more comments
I am reading in CSV file, after that I use -match to find a pattern I am looking for. I now have all of my matches inside a variable called $results. Next, I would like to create a new column and insert the contents of $results into that column. I have been stuck on this for a while, I have attempted to use for loops, forEach loops, if statements, and I cannot seem to get the results that I am looking for. I am new to Powershell, so I may be missing something obvious. Any help is greatly appreciated!
Here is my code:
$target = "This is the path to the .CSV file"
$pattern = '(V-d*)'
$TestFile = (Get-Content $target)
$results = $TestFile | Select-String $pattern -AllMatches
$results.Matches.Value
#$TestFile -replace '(V-d*)',' '
$NewFile = ConvertFrom-Csv $TestFile| Select-Object *,@{Name='Generic
Header';Expression={"Unsure of how to input data here without having all
data in same row"}}|export-csv ' Path for Exporting New .CSV file' -notype
powershell
Can you show us some part of the CSV file (sanitized of course)
– Theo
Jan 2 at 20:06
I cannot, all I am doing is taking strings from one column, storing them in results, creating new column, inserting contents of results into the new column.
– user8284691
Jan 2 at 20:11
So, is your input file really a CSV file (multiple columns, headers) or just a text file with strings on separate lines?
– Theo
Jan 2 at 20:13
Still unclear to me what you are after, insert/append the new column to what? To get the results in one column =>$NewColumn= $result -join ','
– LotPings
Jan 2 at 20:13
1
Hard to help without some sample input.
– Bill_Stewart
Jan 2 at 20:47
|
show 3 more comments
I am reading in CSV file, after that I use -match to find a pattern I am looking for. I now have all of my matches inside a variable called $results. Next, I would like to create a new column and insert the contents of $results into that column. I have been stuck on this for a while, I have attempted to use for loops, forEach loops, if statements, and I cannot seem to get the results that I am looking for. I am new to Powershell, so I may be missing something obvious. Any help is greatly appreciated!
Here is my code:
$target = "This is the path to the .CSV file"
$pattern = '(V-d*)'
$TestFile = (Get-Content $target)
$results = $TestFile | Select-String $pattern -AllMatches
$results.Matches.Value
#$TestFile -replace '(V-d*)',' '
$NewFile = ConvertFrom-Csv $TestFile| Select-Object *,@{Name='Generic
Header';Expression={"Unsure of how to input data here without having all
data in same row"}}|export-csv ' Path for Exporting New .CSV file' -notype
powershell
I am reading in CSV file, after that I use -match to find a pattern I am looking for. I now have all of my matches inside a variable called $results. Next, I would like to create a new column and insert the contents of $results into that column. I have been stuck on this for a while, I have attempted to use for loops, forEach loops, if statements, and I cannot seem to get the results that I am looking for. I am new to Powershell, so I may be missing something obvious. Any help is greatly appreciated!
Here is my code:
$target = "This is the path to the .CSV file"
$pattern = '(V-d*)'
$TestFile = (Get-Content $target)
$results = $TestFile | Select-String $pattern -AllMatches
$results.Matches.Value
#$TestFile -replace '(V-d*)',' '
$NewFile = ConvertFrom-Csv $TestFile| Select-Object *,@{Name='Generic
Header';Expression={"Unsure of how to input data here without having all
data in same row"}}|export-csv ' Path for Exporting New .CSV file' -notype
powershell
powershell
asked Jan 2 at 19:59
user8284691user8284691
34
34
Can you show us some part of the CSV file (sanitized of course)
– Theo
Jan 2 at 20:06
I cannot, all I am doing is taking strings from one column, storing them in results, creating new column, inserting contents of results into the new column.
– user8284691
Jan 2 at 20:11
So, is your input file really a CSV file (multiple columns, headers) or just a text file with strings on separate lines?
– Theo
Jan 2 at 20:13
Still unclear to me what you are after, insert/append the new column to what? To get the results in one column =>$NewColumn= $result -join ','
– LotPings
Jan 2 at 20:13
1
Hard to help without some sample input.
– Bill_Stewart
Jan 2 at 20:47
|
show 3 more comments
Can you show us some part of the CSV file (sanitized of course)
– Theo
Jan 2 at 20:06
I cannot, all I am doing is taking strings from one column, storing them in results, creating new column, inserting contents of results into the new column.
– user8284691
Jan 2 at 20:11
So, is your input file really a CSV file (multiple columns, headers) or just a text file with strings on separate lines?
– Theo
Jan 2 at 20:13
Still unclear to me what you are after, insert/append the new column to what? To get the results in one column =>$NewColumn= $result -join ','
– LotPings
Jan 2 at 20:13
1
Hard to help without some sample input.
– Bill_Stewart
Jan 2 at 20:47
Can you show us some part of the CSV file (sanitized of course)
– Theo
Jan 2 at 20:06
Can you show us some part of the CSV file (sanitized of course)
– Theo
Jan 2 at 20:06
I cannot, all I am doing is taking strings from one column, storing them in results, creating new column, inserting contents of results into the new column.
– user8284691
Jan 2 at 20:11
I cannot, all I am doing is taking strings from one column, storing them in results, creating new column, inserting contents of results into the new column.
– user8284691
Jan 2 at 20:11
So, is your input file really a CSV file (multiple columns, headers) or just a text file with strings on separate lines?
– Theo
Jan 2 at 20:13
So, is your input file really a CSV file (multiple columns, headers) or just a text file with strings on separate lines?
– Theo
Jan 2 at 20:13
Still unclear to me what you are after, insert/append the new column to what? To get the results in one column =>
$NewColumn= $result -join ','
– LotPings
Jan 2 at 20:13
Still unclear to me what you are after, insert/append the new column to what? To get the results in one column =>
$NewColumn= $result -join ','
– LotPings
Jan 2 at 20:13
1
1
Hard to help without some sample input.
– Bill_Stewart
Jan 2 at 20:47
Hard to help without some sample input.
– Bill_Stewart
Jan 2 at 20:47
|
show 3 more comments
2 Answers
2
active
oldest
votes
Sample csv file with pattern in varying columns before
> import-csv .SO_54012419.csv
col1 col2 col3
---- ---- ----
foo bar V-123
V-345 foo bar
bar V-789 foo
running this script:
$target = ".SO_54012419.CSV"
$pattern = '(V-d*)'
$csvdata = Import-Csv $target | Select-Object *,Result
foreach($row in $csvdata){
if ($row -match $pattern){
$Row.Result = $Matches[1]
}
}
$csvdata
$csvdata | Export-Csv 'Path for Exporting New.CSV' -NoTypeInformation
and after:
col1 col2 col3 Result
---- ---- ---- ------
foo bar V-123 V-123
V-345 foo bar V-345
bar V-789 foo V-789
Thank you for your answer, this helped tremendously. Can you please explain the significance of using $Matches[1], I know matches returns every matched item, but this is the first I've seen the use of [1], again I'm new to P-Shell. Thanks
– user8284691
Jan 2 at 21:10
The-match
operator fills the $Matches collection, where $Matches[0] represents the whole input, $Matches[1] the first capture group in the pattern()
$Matches[2] the 2nd etc. SeeGet-Help about_comparison_operators
or view online
– LotPings
Jan 2 at 21:17
Thanks for the info.! Been a big help!
– user8284691
Jan 3 at 10:42
add a comment |
If I understand the question correctly, I think this should do it:
$target = "This is the path to the .CSV file"
$pattern = '(V-d*)'
$column = 'The name of the column to perform the regex match on'
# Read the input file as array of PSCustomObjects
$content = Import-Csv $target
# Do a foreach loop on each of the objects in the $content array
# and perform the regex -match on it. Add a new property (column) to every
# object in the array with the result of your regex match.
# Add an empty string if no match was found.
foreach ($item in $content) {
if ($item.$column -match $pattern) {
$item | Add-Member -MemberType NoteProperty -Name 'Result' -Value $matches[1]
}
else {
$item | Add-Member -MemberType NoteProperty -Name 'Result' -Value ''
}
}
# now use Export-Csv to write the new file complete with the new 'Result' header
$content | Export-Csv 'Path for Exporting New .CSV file' -NoTypeInformation
Hmm displays the header, but the column is empty.
– user8284691
Jan 2 at 20:40
Are you sure you set the correct header name in the$column
variable then?
– Theo
Jan 2 at 20:42
That makes more sense than first treating the csv as text (unless the match could be in any column). ASelect-Object
with a calculated property could also contain the if command.
– LotPings
Jan 2 at 20:43
1
@LotPings I agree. The OP however is not willing to show some of his input csv file, but he did say "all I am doing is taking strings from one column".
– Theo
Jan 2 at 20:44
@Theo thank you for your time, I was able to get the desired result using another example. Again, apologize for not being able to show a scrubbed version, but do to the nature of my work I could not. Thanks again.
– user8284691
Jan 2 at 21:12
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012419%2fmake-column-and-insert-array-contents-inside-the-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sample csv file with pattern in varying columns before
> import-csv .SO_54012419.csv
col1 col2 col3
---- ---- ----
foo bar V-123
V-345 foo bar
bar V-789 foo
running this script:
$target = ".SO_54012419.CSV"
$pattern = '(V-d*)'
$csvdata = Import-Csv $target | Select-Object *,Result
foreach($row in $csvdata){
if ($row -match $pattern){
$Row.Result = $Matches[1]
}
}
$csvdata
$csvdata | Export-Csv 'Path for Exporting New.CSV' -NoTypeInformation
and after:
col1 col2 col3 Result
---- ---- ---- ------
foo bar V-123 V-123
V-345 foo bar V-345
bar V-789 foo V-789
Thank you for your answer, this helped tremendously. Can you please explain the significance of using $Matches[1], I know matches returns every matched item, but this is the first I've seen the use of [1], again I'm new to P-Shell. Thanks
– user8284691
Jan 2 at 21:10
The-match
operator fills the $Matches collection, where $Matches[0] represents the whole input, $Matches[1] the first capture group in the pattern()
$Matches[2] the 2nd etc. SeeGet-Help about_comparison_operators
or view online
– LotPings
Jan 2 at 21:17
Thanks for the info.! Been a big help!
– user8284691
Jan 3 at 10:42
add a comment |
Sample csv file with pattern in varying columns before
> import-csv .SO_54012419.csv
col1 col2 col3
---- ---- ----
foo bar V-123
V-345 foo bar
bar V-789 foo
running this script:
$target = ".SO_54012419.CSV"
$pattern = '(V-d*)'
$csvdata = Import-Csv $target | Select-Object *,Result
foreach($row in $csvdata){
if ($row -match $pattern){
$Row.Result = $Matches[1]
}
}
$csvdata
$csvdata | Export-Csv 'Path for Exporting New.CSV' -NoTypeInformation
and after:
col1 col2 col3 Result
---- ---- ---- ------
foo bar V-123 V-123
V-345 foo bar V-345
bar V-789 foo V-789
Thank you for your answer, this helped tremendously. Can you please explain the significance of using $Matches[1], I know matches returns every matched item, but this is the first I've seen the use of [1], again I'm new to P-Shell. Thanks
– user8284691
Jan 2 at 21:10
The-match
operator fills the $Matches collection, where $Matches[0] represents the whole input, $Matches[1] the first capture group in the pattern()
$Matches[2] the 2nd etc. SeeGet-Help about_comparison_operators
or view online
– LotPings
Jan 2 at 21:17
Thanks for the info.! Been a big help!
– user8284691
Jan 3 at 10:42
add a comment |
Sample csv file with pattern in varying columns before
> import-csv .SO_54012419.csv
col1 col2 col3
---- ---- ----
foo bar V-123
V-345 foo bar
bar V-789 foo
running this script:
$target = ".SO_54012419.CSV"
$pattern = '(V-d*)'
$csvdata = Import-Csv $target | Select-Object *,Result
foreach($row in $csvdata){
if ($row -match $pattern){
$Row.Result = $Matches[1]
}
}
$csvdata
$csvdata | Export-Csv 'Path for Exporting New.CSV' -NoTypeInformation
and after:
col1 col2 col3 Result
---- ---- ---- ------
foo bar V-123 V-123
V-345 foo bar V-345
bar V-789 foo V-789
Sample csv file with pattern in varying columns before
> import-csv .SO_54012419.csv
col1 col2 col3
---- ---- ----
foo bar V-123
V-345 foo bar
bar V-789 foo
running this script:
$target = ".SO_54012419.CSV"
$pattern = '(V-d*)'
$csvdata = Import-Csv $target | Select-Object *,Result
foreach($row in $csvdata){
if ($row -match $pattern){
$Row.Result = $Matches[1]
}
}
$csvdata
$csvdata | Export-Csv 'Path for Exporting New.CSV' -NoTypeInformation
and after:
col1 col2 col3 Result
---- ---- ---- ------
foo bar V-123 V-123
V-345 foo bar V-345
bar V-789 foo V-789
edited Jan 2 at 21:37
answered Jan 2 at 20:53


LotPingsLotPings
20.1k61633
20.1k61633
Thank you for your answer, this helped tremendously. Can you please explain the significance of using $Matches[1], I know matches returns every matched item, but this is the first I've seen the use of [1], again I'm new to P-Shell. Thanks
– user8284691
Jan 2 at 21:10
The-match
operator fills the $Matches collection, where $Matches[0] represents the whole input, $Matches[1] the first capture group in the pattern()
$Matches[2] the 2nd etc. SeeGet-Help about_comparison_operators
or view online
– LotPings
Jan 2 at 21:17
Thanks for the info.! Been a big help!
– user8284691
Jan 3 at 10:42
add a comment |
Thank you for your answer, this helped tremendously. Can you please explain the significance of using $Matches[1], I know matches returns every matched item, but this is the first I've seen the use of [1], again I'm new to P-Shell. Thanks
– user8284691
Jan 2 at 21:10
The-match
operator fills the $Matches collection, where $Matches[0] represents the whole input, $Matches[1] the first capture group in the pattern()
$Matches[2] the 2nd etc. SeeGet-Help about_comparison_operators
or view online
– LotPings
Jan 2 at 21:17
Thanks for the info.! Been a big help!
– user8284691
Jan 3 at 10:42
Thank you for your answer, this helped tremendously. Can you please explain the significance of using $Matches[1], I know matches returns every matched item, but this is the first I've seen the use of [1], again I'm new to P-Shell. Thanks
– user8284691
Jan 2 at 21:10
Thank you for your answer, this helped tremendously. Can you please explain the significance of using $Matches[1], I know matches returns every matched item, but this is the first I've seen the use of [1], again I'm new to P-Shell. Thanks
– user8284691
Jan 2 at 21:10
The
-match
operator fills the $Matches collection, where $Matches[0] represents the whole input, $Matches[1] the first capture group in the pattern ()
$Matches[2] the 2nd etc. See Get-Help about_comparison_operators
or view online– LotPings
Jan 2 at 21:17
The
-match
operator fills the $Matches collection, where $Matches[0] represents the whole input, $Matches[1] the first capture group in the pattern ()
$Matches[2] the 2nd etc. See Get-Help about_comparison_operators
or view online– LotPings
Jan 2 at 21:17
Thanks for the info.! Been a big help!
– user8284691
Jan 3 at 10:42
Thanks for the info.! Been a big help!
– user8284691
Jan 3 at 10:42
add a comment |
If I understand the question correctly, I think this should do it:
$target = "This is the path to the .CSV file"
$pattern = '(V-d*)'
$column = 'The name of the column to perform the regex match on'
# Read the input file as array of PSCustomObjects
$content = Import-Csv $target
# Do a foreach loop on each of the objects in the $content array
# and perform the regex -match on it. Add a new property (column) to every
# object in the array with the result of your regex match.
# Add an empty string if no match was found.
foreach ($item in $content) {
if ($item.$column -match $pattern) {
$item | Add-Member -MemberType NoteProperty -Name 'Result' -Value $matches[1]
}
else {
$item | Add-Member -MemberType NoteProperty -Name 'Result' -Value ''
}
}
# now use Export-Csv to write the new file complete with the new 'Result' header
$content | Export-Csv 'Path for Exporting New .CSV file' -NoTypeInformation
Hmm displays the header, but the column is empty.
– user8284691
Jan 2 at 20:40
Are you sure you set the correct header name in the$column
variable then?
– Theo
Jan 2 at 20:42
That makes more sense than first treating the csv as text (unless the match could be in any column). ASelect-Object
with a calculated property could also contain the if command.
– LotPings
Jan 2 at 20:43
1
@LotPings I agree. The OP however is not willing to show some of his input csv file, but he did say "all I am doing is taking strings from one column".
– Theo
Jan 2 at 20:44
@Theo thank you for your time, I was able to get the desired result using another example. Again, apologize for not being able to show a scrubbed version, but do to the nature of my work I could not. Thanks again.
– user8284691
Jan 2 at 21:12
add a comment |
If I understand the question correctly, I think this should do it:
$target = "This is the path to the .CSV file"
$pattern = '(V-d*)'
$column = 'The name of the column to perform the regex match on'
# Read the input file as array of PSCustomObjects
$content = Import-Csv $target
# Do a foreach loop on each of the objects in the $content array
# and perform the regex -match on it. Add a new property (column) to every
# object in the array with the result of your regex match.
# Add an empty string if no match was found.
foreach ($item in $content) {
if ($item.$column -match $pattern) {
$item | Add-Member -MemberType NoteProperty -Name 'Result' -Value $matches[1]
}
else {
$item | Add-Member -MemberType NoteProperty -Name 'Result' -Value ''
}
}
# now use Export-Csv to write the new file complete with the new 'Result' header
$content | Export-Csv 'Path for Exporting New .CSV file' -NoTypeInformation
Hmm displays the header, but the column is empty.
– user8284691
Jan 2 at 20:40
Are you sure you set the correct header name in the$column
variable then?
– Theo
Jan 2 at 20:42
That makes more sense than first treating the csv as text (unless the match could be in any column). ASelect-Object
with a calculated property could also contain the if command.
– LotPings
Jan 2 at 20:43
1
@LotPings I agree. The OP however is not willing to show some of his input csv file, but he did say "all I am doing is taking strings from one column".
– Theo
Jan 2 at 20:44
@Theo thank you for your time, I was able to get the desired result using another example. Again, apologize for not being able to show a scrubbed version, but do to the nature of my work I could not. Thanks again.
– user8284691
Jan 2 at 21:12
add a comment |
If I understand the question correctly, I think this should do it:
$target = "This is the path to the .CSV file"
$pattern = '(V-d*)'
$column = 'The name of the column to perform the regex match on'
# Read the input file as array of PSCustomObjects
$content = Import-Csv $target
# Do a foreach loop on each of the objects in the $content array
# and perform the regex -match on it. Add a new property (column) to every
# object in the array with the result of your regex match.
# Add an empty string if no match was found.
foreach ($item in $content) {
if ($item.$column -match $pattern) {
$item | Add-Member -MemberType NoteProperty -Name 'Result' -Value $matches[1]
}
else {
$item | Add-Member -MemberType NoteProperty -Name 'Result' -Value ''
}
}
# now use Export-Csv to write the new file complete with the new 'Result' header
$content | Export-Csv 'Path for Exporting New .CSV file' -NoTypeInformation
If I understand the question correctly, I think this should do it:
$target = "This is the path to the .CSV file"
$pattern = '(V-d*)'
$column = 'The name of the column to perform the regex match on'
# Read the input file as array of PSCustomObjects
$content = Import-Csv $target
# Do a foreach loop on each of the objects in the $content array
# and perform the regex -match on it. Add a new property (column) to every
# object in the array with the result of your regex match.
# Add an empty string if no match was found.
foreach ($item in $content) {
if ($item.$column -match $pattern) {
$item | Add-Member -MemberType NoteProperty -Name 'Result' -Value $matches[1]
}
else {
$item | Add-Member -MemberType NoteProperty -Name 'Result' -Value ''
}
}
# now use Export-Csv to write the new file complete with the new 'Result' header
$content | Export-Csv 'Path for Exporting New .CSV file' -NoTypeInformation
edited Jan 2 at 20:40
answered Jan 2 at 20:33
TheoTheo
6,0823521
6,0823521
Hmm displays the header, but the column is empty.
– user8284691
Jan 2 at 20:40
Are you sure you set the correct header name in the$column
variable then?
– Theo
Jan 2 at 20:42
That makes more sense than first treating the csv as text (unless the match could be in any column). ASelect-Object
with a calculated property could also contain the if command.
– LotPings
Jan 2 at 20:43
1
@LotPings I agree. The OP however is not willing to show some of his input csv file, but he did say "all I am doing is taking strings from one column".
– Theo
Jan 2 at 20:44
@Theo thank you for your time, I was able to get the desired result using another example. Again, apologize for not being able to show a scrubbed version, but do to the nature of my work I could not. Thanks again.
– user8284691
Jan 2 at 21:12
add a comment |
Hmm displays the header, but the column is empty.
– user8284691
Jan 2 at 20:40
Are you sure you set the correct header name in the$column
variable then?
– Theo
Jan 2 at 20:42
That makes more sense than first treating the csv as text (unless the match could be in any column). ASelect-Object
with a calculated property could also contain the if command.
– LotPings
Jan 2 at 20:43
1
@LotPings I agree. The OP however is not willing to show some of his input csv file, but he did say "all I am doing is taking strings from one column".
– Theo
Jan 2 at 20:44
@Theo thank you for your time, I was able to get the desired result using another example. Again, apologize for not being able to show a scrubbed version, but do to the nature of my work I could not. Thanks again.
– user8284691
Jan 2 at 21:12
Hmm displays the header, but the column is empty.
– user8284691
Jan 2 at 20:40
Hmm displays the header, but the column is empty.
– user8284691
Jan 2 at 20:40
Are you sure you set the correct header name in the
$column
variable then?– Theo
Jan 2 at 20:42
Are you sure you set the correct header name in the
$column
variable then?– Theo
Jan 2 at 20:42
That makes more sense than first treating the csv as text (unless the match could be in any column). A
Select-Object
with a calculated property could also contain the if command.– LotPings
Jan 2 at 20:43
That makes more sense than first treating the csv as text (unless the match could be in any column). A
Select-Object
with a calculated property could also contain the if command.– LotPings
Jan 2 at 20:43
1
1
@LotPings I agree. The OP however is not willing to show some of his input csv file, but he did say "all I am doing is taking strings from one column".
– Theo
Jan 2 at 20:44
@LotPings I agree. The OP however is not willing to show some of his input csv file, but he did say "all I am doing is taking strings from one column".
– Theo
Jan 2 at 20:44
@Theo thank you for your time, I was able to get the desired result using another example. Again, apologize for not being able to show a scrubbed version, but do to the nature of my work I could not. Thanks again.
– user8284691
Jan 2 at 21:12
@Theo thank you for your time, I was able to get the desired result using another example. Again, apologize for not being able to show a scrubbed version, but do to the nature of my work I could not. Thanks again.
– user8284691
Jan 2 at 21:12
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012419%2fmake-column-and-insert-array-contents-inside-the-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you show us some part of the CSV file (sanitized of course)
– Theo
Jan 2 at 20:06
I cannot, all I am doing is taking strings from one column, storing them in results, creating new column, inserting contents of results into the new column.
– user8284691
Jan 2 at 20:11
So, is your input file really a CSV file (multiple columns, headers) or just a text file with strings on separate lines?
– Theo
Jan 2 at 20:13
Still unclear to me what you are after, insert/append the new column to what? To get the results in one column =>
$NewColumn= $result -join ','
– LotPings
Jan 2 at 20:13
1
Hard to help without some sample input.
– Bill_Stewart
Jan 2 at 20:47