0
1

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.

正規表現を使ってログやテキストデータを見やすく整形する簡単な方法

Posted at

ログファイルやテキストデータを扱っていると定型的な文字の羅列で見づらいことがありませんか?
そんな時正規表現をうまく使えば、ぱっと見で見やすく整形できて効率的なことがあるので簡単な置換の一例をご紹介します。

,(カンマ)で改行させる

ログファイルやcsvやSQLのselect文など,(カンマ)をセパレータとして使用しているファイルだと
横に長くなり見づらいことがあります。
そんな時はエディタの正規表現をONにして

,

,\r\n

に置換すると,,改行に一括で置換できます。

スクリーンショット 2019-08-26 12.06.22.png

windowsの場合はCRLFで\r\n
MacやLinux系の場合はLFで\nです。

※MacはOS9以前はCRですが、10以降はLFなのでLinuxと同様で覚えて大丈夫だと思います。

正規表現は奥が深いので使いこなせるととても生産性が上がります。

0
1
1

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?