Created
April 7, 2020 22:04
-
-
Save tylerlmz1/7496e30b0354565a5f03f9fc669f3780 to your computer and use it in GitHub Desktop.
extract specified line range from a text file to a new text file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get source and destination file name | |
$fileName = Read-Host -Prompt 'Source file name' | |
$content = Get-Content $fileName | |
$newFileName = Read-Host -Prompt 'New file name' | |
# get line number | |
$start = Read-Host -Prompt 'Starting line number' | |
$end = Read-Host -Prompt 'Ending line number' | |
# write target lines from source file into destination file | |
Get-Content -Path $fileName | Select-Object -Index ($start..$end) | Foreach-Object { | |
Add-Content "./$newFileName" $PSItem | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment