LoginSignup
219
163

More than 3 years have passed since last update.

Visual Studio Code 重複行を削除する

Last updated at Posted at 2018-05-20

目的

重複したテキストデータを削除したい。

手順

1. 行をソートする

  • Command + A でソートする行を範囲選択する
  • Command + Shift + P
    • >Sort Lines Ascending 昇順または降順に並び替える

2. 正規表現で重複行を削除する

  • 検索窓を表示する: Command + F
  • 正規表現を使用する: Command + option + R
  • 検索ボックスへ入力: (^.*$)(\n(^\1$)){1,}
  • 置換ボックスへ入力: $1
  • すべて置換: Command + option + Enter

キャプチャ動画

17a2626a47f8eeffd061f1e87097edec.gif

補足

(^.*$)\n(^\1$)$1 の正規表現の補足です。

まず、正規表現では括弧で囲われた部分は変数に代入されます。
括弧の数に応じて $1,$2,$3... と代入されていきます。
\1 は前方で記憶した文字列をマッチしています。

改行を挟んで二行続けて同じかチェックして、一行目に置換するイメージです。

参考

219
163
2

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
219
163