2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

csvファイルの重複行を削除して出力する

Last updated at Posted at 2019-07-07

したいこと

DBにCSVファイルからデータ取り込みしようとしたら重複があってエラーになったので取り込み前にクレンジング

使用するコマンドレット|

コマンドレット 内容
Get-Content csvを読み込む
Sort-Unique ソートして重複削除
Sort-Object ソート
Get-Unique 重複削除

2通りの方法がある

  • Sort-Unique を使う方法

  • Get-Unique を使う方法
    こちらを使う場合はソートそしてからじゃないと削除できないので
    Sort-Objectと併用する

サンプルコード

# 取込みファイルフルパス
[string]$filepath = $inifilefldr + $imptfile

# Sort-Uniqueを使う場合 
Get-Content -Path $filepath | sort -Unique

# Get-Uniqueを使う場合
Get-Content -Path $filepath | Sort-Object | Get-Unique -AsString
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?