0
0

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 3 years have passed since last update.

改行コード変換で悩まない、簡単変換

Last updated at Posted at 2020-02-05

経緯

改行コード変換で調べるとtrがよく出てくるが、改行コード指定するのだるい&変換うまくいかない場合があった
もっと簡単なの無いかと探したらnkfで簡単に出来るやん

やってみる

環境がMacなのでデフォが改行コードLF

$ file sample
sample: ASCII text
$ od -c sample
0000000   a   a   a   a   a   a  \n   b   b   b   b   b   b  \n   c   c
0000020   c   c   c   c  \n
0000025

CRLFに変換(Windows)

$ nkf -c sample > sample_CRLF
$ file sample_CRLF
sample_CRLF: ASCII text, with CRLF line terminators
$ od -c sample_CRLF
0000000   a   a   a   a   a   a  \r  \n   b   b   b   b   b   b  \r  \n
0000020   c   c   c   c   c   c  \r  \n
0000030

LFに変換(Linux)

$ nkf -d sample_CRLF > sample_LF
$ file sample_LF
sample_LF: ASCII text
$ od -c sample_LF
0000000   a   a   a   a   a   a  \n   b   b   b   b   b   b  \n   c   c
0000020   c   c   c   c  \n
0000025
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?