Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge/combine two lists line by line?

I have two lists stored in variables: $list1 and $list2, for example:

$list1:

a
b
c
d

$list2:

1
2
3
4

How do I merge them together line by line so that I end up with:

a1
b2
c3
d4

I have tried using array (@) but it just combines them one after the other, not line by line, example:

$list1 = @(command)
$list1 += @($list2)
like image 361
Rakha Avatar asked Oct 19 '25 01:10

Rakha


1 Answers

If you prefer pipelining, you can also do it in one line:

0 .. ($list1.count -1) | ForEach-Object { $list1[$_]+$list2[$_] }
like image 50
Martin Brandl Avatar answered Oct 21 '25 14:10

Martin Brandl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!