Skip to content

Instantly share code, notes, and snippets.

@tackme31
Created January 20, 2022 01:58
Show Gist options
  • Save tackme31/e2b2a136b17ce23a4b8c43725060b383 to your computer and use it in GitHub Desktop.
Save tackme31/e2b2a136b17ce23a4b8c43725060b383 to your computer and use it in GitHub Desktop.
A PowerShell commandlet like bash's 'nl' command.
Function Join-LineNumbers {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True)]
[string[]]$Lines
)
begin {
$private:i = 1
}
process {
foreach ($line in $Lines) {
Write-Output "$private:i`t$line"
$private:i++
}
}
}
Set-Alias -Name nl -Value Join-LineNumbers -Option None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment