Hi powerShell,
I am written script in powershell:
$input = @(Get-Content H:\bb.txt)
$bb = @(foreach($line in $input){
$line
})
Get-Content H:\aa.txt | ConvertFrom-Csv -Header (1…2)|
ForEach-Object { $.‘2’ = $bb ; $ } |
ConvertTo-Csv -NoTypeInformation |
Select-Object -Skip 1 |
ForEach-Object { $_ -replace ‘"’,‘’ }
Where aa.txt:
aa
aa
aa
aa
Where bb.txt:
bb
bb
bb
bb
output:
aa,System.Object
aa,System.Object
aa,System.Object
aa,System.Object
The display output should like this as below:
aa,bb
aa,bb
aa,bb
aa,bb
Any idea?
Thanks
here ForEach-Object { $.‘2’ = $bb ; $ } |
you assign array $bb to column 2 of every line from $aa
and after converting it to csv you get array csv representation as `System.Object`
if you need to combine every line of aa.txt with every line of bb.txt
you should at least assign it as $_.‘2’ = $bb[$index] where $index is line number.
may be you should convert your cycle to
for ($index=0; $index -lt $bb.count; $index++){
$aa[$index].‘2’ = $bb[$index]
}
form
what is $aa? I do not get it. I tired this one but error
$input = @(Get-Content H:\bb.txt)
$bb = foreach($line in $input){
}
Get-Content H:\aa.txt | ConvertFrom-Csv -Header (1…2)|
#ForEach-Object { $.‘2’ = $test ; $ } |
@(for($i=0; $i -lt $bb.count; $i++){ $aa[$i].‘2’ = $bb[$i]}form)
ConvertTo-Csv -NoTypeInformation |
Select-Object -Skip 1 |
ForEach-Object { $_ -replace ‘"’,‘’ }
I can write all script for you but this way you never learn :
$aa is the content of aa.txt as well as $bb is content of bb.txt
btw,
$input = @(Get-Content H:\bb.txt)
$bb = @(foreach($line in $input){
$line
})
is equal to
$bb=Get-Content H:\bb.txt