[LINUX] Easy conversion without worrying about line feed code conversion

Background

When I check with line feed code conversion, tr often appears, but there were cases where specifying the line feed code was tedious & conversion did not work. If you look for something easier, you can easily do it with nkf.

Try

Since the environment is Mac, the default is line feed code 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

Convert to 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

Convert to 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

Recommended Posts

Easy conversion without worrying about line feed code conversion
Shell command to visualize line feed code