I want to split the powershell-command txt document

Viewed 47

I am a Windows 10 user.

This is the command below.

powershell -command "& {get-content log.txt|select-object -first 100}" >out_log111.txt

This is what I saw on the website. (Success!)

.

I applied it as below.

powershell -command "& {get-content log.txt|select-object -first (100..200)}" >out_log222.txt

https://i.stack.imgur.com/4jFGX.png

An error occurs. (Failed)

.

.

I want to split the log.txt document. I want to print from the first 100 onwards to 200.

And the rest.

I'd like to print out 200 to 300 next time.

in order

200~300 out_log333.txt

300~400 out_log444.txt

I'm going to file a long log.txt file

I'd like to divide by numbers in cmd. (bat file)

in hundred lines

Thank you.

1 Answers

You should be using -Index, not -First, and because the indexing begins at 0, the command you should be using is:

@%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile^
 "Get-Content -Path '.\log.txt'"^
 " | Select-Object -Index (99..199) > '.\out_log222.txt'"

I have split the command over three lines for readability, but you could leave it as one if you preferred.

Related