PowerShell/PowerShellでheadとtailを実現する
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* PowerShellでheadとtailを実現する [#vb3c79fd]
Linux(UNIX)にあるheadとtailコマンドをPowerShellで実現する...
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
* Select-Objectの-firstと-lastオプション [#l2b02650]
Select-Objectの-firstと-lastオプションを使用することによ...
headとtailコマンドと同様の機能を実現することができます。
** -firstオプション [#l9376d57]
指定した数値分、先頭行を表示します。
Select-Object -first 数値
以下に実際に動作させた例を記します。
以下の例では、Windowsフォルダのファイルリストから先頭の5...
PS C:\Windows> Get-ChildItem * | Select-Object -first 5
Directory: C:\Windows
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2009/07/14 14:32 addins
d----- 2016/04/04 9:14 AppCompat
d----- 2017/07/03 9:42 AppPatch
d-r-s- 2017/05/10 10:31 assembly
d----- 2016/04/01 10:51 AsusIns...
PS C:\Windows> Get-ChildItem -Name * | Select-Object -fi...
addins
AppCompat
AppPatch
assembly
AsusInstAll
以下の例では、最終更新日でソートしたファイルリストの先頭...
PS C:\Windows> Get-ChildItem * | Sort-Object { $_.LastWr...
Directory: C:\Windows
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2009/06/11 5:30 53551 Profess...
-a---- 2009/06/11 5:31 48201 Starter...
-a---- 2009/06/11 5:36 1405 msdfmap...
-a---l 2009/06/11 5:52 316640 WMSysPr...
------ 2009/06/11 6:08 219 system....
PS C:\Windows> Get-ChildItem * | Sort-Object -Descending...
Directory: C:\Windows
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2017/07/05 12:26 Temp
d----- 2017/07/05 9:17 System32
d----- 2017/07/05 9:05 inf
-a---- 2017/07/05 9:01 9204 cfgall....
-a---- 2017/07/05 9:01 23260 TMFilte...
以下の例では、ファイルでソートしたファイルリストの先頭か...
PS C:\Windows> Get-ChildItem * | Sort-Object { $_.Length...
Directory: C:\Windows
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2016/04/01 10:51 0 Ascd_er...
-a---- 2016/04/01 10:51 0 scd.ini
-a---- 2017/05/22 16:56 0 setuper...
d----- 2011/04/12 17:01 security
d----- 2009/07/14 14:32 schemas
PS C:\Windows> Get-ChildItem * | Sort-Object -Descending...
Directory: C:\Windows
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2016/04/01 10:11 7831039 OFCNT.LOG
-a---l 2016/01/22 14:19 3231232 explore...
--r--- 2013/09/13 19:44 2080472 RtlExUp...
2017/07/04 14:59 1076207 Windows...
-a---l 2017/06/02 17:10 733696 HelpPan...
** -lastオプション [#ca3a6f1a]
指定した数値分、最終行からさかのぼり表示します。
Select-Object -last 数値
以下に実際に動作させた例を記します。
PS D:\> Get-Content .\text.txt
1 one
2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
9 nine
10 ten
PS D:\> Get-Content .\text.txt | Select-Object -first 5
1 one
2 two
3 three
4 four
5 five
PS D:\> Get-Content .\text.txt | Select-Object -last 5
6 six
7 seven
8 eight
9 nine
10 ten
以上、PowerShellでheadとtailと同様な動作を実現する、Selec...
#htmlinsertpcsp(win-btm.html,win-sp.html)
終了行:
#navi(../)
* PowerShellでheadとtailを実現する [#vb3c79fd]
Linux(UNIX)にあるheadとtailコマンドをPowerShellで実現する...
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
* Select-Objectの-firstと-lastオプション [#l2b02650]
Select-Objectの-firstと-lastオプションを使用することによ...
headとtailコマンドと同様の機能を実現することができます。
** -firstオプション [#l9376d57]
指定した数値分、先頭行を表示します。
Select-Object -first 数値
以下に実際に動作させた例を記します。
以下の例では、Windowsフォルダのファイルリストから先頭の5...
PS C:\Windows> Get-ChildItem * | Select-Object -first 5
Directory: C:\Windows
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2009/07/14 14:32 addins
d----- 2016/04/04 9:14 AppCompat
d----- 2017/07/03 9:42 AppPatch
d-r-s- 2017/05/10 10:31 assembly
d----- 2016/04/01 10:51 AsusIns...
PS C:\Windows> Get-ChildItem -Name * | Select-Object -fi...
addins
AppCompat
AppPatch
assembly
AsusInstAll
以下の例では、最終更新日でソートしたファイルリストの先頭...
PS C:\Windows> Get-ChildItem * | Sort-Object { $_.LastWr...
Directory: C:\Windows
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2009/06/11 5:30 53551 Profess...
-a---- 2009/06/11 5:31 48201 Starter...
-a---- 2009/06/11 5:36 1405 msdfmap...
-a---l 2009/06/11 5:52 316640 WMSysPr...
------ 2009/06/11 6:08 219 system....
PS C:\Windows> Get-ChildItem * | Sort-Object -Descending...
Directory: C:\Windows
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2017/07/05 12:26 Temp
d----- 2017/07/05 9:17 System32
d----- 2017/07/05 9:05 inf
-a---- 2017/07/05 9:01 9204 cfgall....
-a---- 2017/07/05 9:01 23260 TMFilte...
以下の例では、ファイルでソートしたファイルリストの先頭か...
PS C:\Windows> Get-ChildItem * | Sort-Object { $_.Length...
Directory: C:\Windows
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2016/04/01 10:51 0 Ascd_er...
-a---- 2016/04/01 10:51 0 scd.ini
-a---- 2017/05/22 16:56 0 setuper...
d----- 2011/04/12 17:01 security
d----- 2009/07/14 14:32 schemas
PS C:\Windows> Get-ChildItem * | Sort-Object -Descending...
Directory: C:\Windows
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2016/04/01 10:11 7831039 OFCNT.LOG
-a---l 2016/01/22 14:19 3231232 explore...
--r--- 2013/09/13 19:44 2080472 RtlExUp...
2017/07/04 14:59 1076207 Windows...
-a---l 2017/06/02 17:10 733696 HelpPan...
** -lastオプション [#ca3a6f1a]
指定した数値分、最終行からさかのぼり表示します。
Select-Object -last 数値
以下に実際に動作させた例を記します。
PS D:\> Get-Content .\text.txt
1 one
2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
9 nine
10 ten
PS D:\> Get-Content .\text.txt | Select-Object -first 5
1 one
2 two
3 three
4 four
5 five
PS D:\> Get-Content .\text.txt | Select-Object -last 5
6 six
7 seven
8 eight
9 nine
10 ten
以上、PowerShellでheadとtailと同様な動作を実現する、Selec...
#htmlinsertpcsp(win-btm.html,win-sp.html)
ページ名: