Question: I'm attempting to combine every two lines of the output of this Powershell command:

```
(((Invoke-WebRequest -Uri "https://www.timeanddate.com/holidays/us/$(Get-Date -Format yyyy)").Content | sls 'id=holidays') -split '<th class="nw" >' | Out-String -Stream) -replace '<|>',',' | ForEach-Object {$_.Split(',')[10,0];}

```

As you can see if you run it it outputs holidays and their date for the current year like so:

```
New Year's Day
Jan 1
World Braille Day
Jan 4
Epiphany
Jan 6
Orthodox Christmas Day
Jan 7
International Programmers' Day
Jan 7

etc.

```

My goal is for the output to be:

```
New Year's Day Jan 1
World Braille Day Jan 4
Epiphany Jan 6
Orthodox Christmas Day Jan 7
International Programmers' Day Jan 7

etc.

```

Any suggestions are welcome (I would like to do this without writing output to a file during the process). Or if there is a more efficient way of doing this I'm open to that as well.

Answer: 
Use a simple `for` loop with a counter that increments by 2 every time:

```
$splitLines = (((Invoke-WebRequest -Uri "https://www.timeanddate.com/holidays/us/$(Get-Date -Format yyyy)").Content | sls 'id=holidays') -split '<th class="nw" >' | Out-String -Stream) -replace '<|>',',' | ForEach-Object {$_.Split(',')[10,0];}

for($i = 0; $i -lt $splitLines.Count; $i += 2){
  $splitLines[$i,($i+1)] -join ' '
}

```
You can do something along those lines. For some reason I have to use modulus 4 here and not 2 because when I split like that it makes every second line empty.

```bsh
$inputData = @"
New Year's Day
Jan 1
World Braille Day
Jan 4
Epiphany
Jan 6
Orthodox Christmas Day
Jan 7
International Programmers' Day
Jan 7
"@

$splitData = $inputData.Split([Environment]::NewLine)

# use a dot here to make the output availabe after the iteration is completed
$splitData | . { 
  begin {
      $output = "" 
      $i = 0
  }
  process {
    if(0 -eq $i % 4) {
      $output += $_ + [Environment]::NewLine
    }
    $i = $i + 1
  }
}

Write-Output $output
# New Year's Day
# World Braille Day
# Epiphany
# Orthodox Christmas Day
# International Programmers' Day

```

*It's not perfect but it works for the given problem I would suggest tinkering with it and make it little more nice. Haven't used PowerShell in a while.*