LoginSignup
0
0

More than 1 year has passed since last update.

powershellでuniq

Last updated at Posted at 2023-04-02

概要

powershellでbashのuniqと同じようなことを行う。

使用例

以下のunixでのコマンドをpowershellで行う

unix.sh
ls | uniq -c -s 3 -w 4

次がpowershellでの方法

powershell.ps1
ls | group -p @{e={$_.name.substring(2,4)}}

または、単純に

powershell2.ps1
ls | group {$_.name.substring(2,4)}

詳細説明

どうも、powershellは@{name="タイトル",expression={式}}というような項目を
表示してくれるようになっている。このsampleはabout_CALCULATED_PROPERTIESという
helpファイルに、いろいろサンプルがある。nameの部分は省略してもよい。

man about_CALCULATED_PROPERTIES とすればでてくる。

powershell.ps1の中でe=としているのはexpressionの略である。

まあ、unixは分かってしまえば有用なオプションが山ほどあるんだがなかなか使いこなせない。

powershellのやり方の方が、なんとなく分かり易くて、いいなあと思った次第。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0