Line Ending Converter
改行コードをCRLF / LF / CR に相互変換します。混在の検出と可視化にも対応。
貼り付け・ファイル読み込みでは元の改行コードをそのまま判定します。 ただし入力欄で手入力・編集するとブラウザの仕様で改行がLFに正規化されるため、判定はLFになります。
テキストを入力すると改行コードを判定します。
How to Use the Line Ending Converter
A line break is not a single universal character. Windows terminates lines with two bytes, carriage return plus line feed (CRLF, 0D 0A). Unix, Linux and modern macOS use a bare line feed (LF, 0A). Classic Mac OS through version 9 used a bare carriage return (CR, 0D). Because the bytes differ, a file written on one platform can confuse tools on another — and the difference is completely invisible in most editors.
Paste text or load a file, and the tool reports how many of each ending it found, whether they are mixed, and how many lines there are. Choose a target ending and the converted text appears immediately, ready to copy or download. Turn on the symbol display to see exactly where each ␍ and ␊ sits.
Symptoms of the Wrong Line Ending
The classic one is bad interpreter: /bin/bash^M. A shell script saved on Windows carries a trailing CR on the shebang line, so the kernel looks for an interpreter literally named /bin/bash\r and fails. In Git, committing CRLF files into a repository that expects LF makes every line show as changed in a diff, burying the real edit. Some parsers also treat a stray CR as part of the last field, producing values with an invisible trailing character that never compare equal.
Mixed Endings
Mixed endings are the worst case: part of the file uses CRLF and part uses LF, usually because different editors touched it. Line counts disagree between tools, diffs become noisy, and search-and-replace behaves inconsistently. This tool flags mixing explicitly so you can normalize the whole file in one pass.
改行コード変換ツールの使い方
テキストを貼り付けるか、ファイルを読み込むと、CRLF・LF・CR がそれぞれ何個あるかを判定します。 種類が混ざっている場合は警告を表示します。変換先を選ぶと即座に変換され、コピーまたは ファイルとしてダウンロードできます。
「改行を記号で表示」をオンにすると、CR を ␍、LF を ␊ として 可視化できます。どこに余分な CR が残っているかを目で確認したいときに使ってください。 この記号は表示専用で、コピーやダウンロードの結果には含まれません。
よくある落とし穴と対処 / Common Pitfalls
| 落とし穴 / Pitfall | 問題 / Problem | 対処 / Fix |
|---|---|---|
| シェルスクリプトがCRLF Shell script saved as CRLF | bad interpreter: /bin/bash^M で起動しない The shebang gains a trailing CR | LFに変換して保存し直す Convert the file to LF |
| Gitで全行が差分になる Every line shows as changed in git diff | 改行コードだけが変わり、実際の変更が埋もれる Real edits are buried in noise | .gitattributes で text=auto 等を宣言し git add --renormalize する Declare .gitattributes and renormalize |
| 改行コードが混在する Mixed endings inside one file | ツールごとに行数が食い違い、置換結果も不安定になる Tools disagree on line counts | ファイル全体を一度に統一する(このツールの変換は全体に適用される) Normalize the whole file at once |
| 末尾の改行の有無 Missing final newline | 最終行に改行がないとPOSIXツールが最後の行を読み飛ばすことがある POSIX tools may skip an unterminated last line | 変換前後で行数表示を見比べて、末尾改行の有無を意識する Check the line count before and after |
| CSVのフィールド内改行 Newlines inside quoted CSV fields | 引用符で囲まれたフィールド内の改行まで一括変換するとデータの意味が変わる Blanket conversion also rewrites in-field newlines | CSVはCSVパーサ経由で扱う。単純な一括変換は避ける Use a CSV parser instead |
言語別コード例 / Code Examples
JavaScript
// いったん LF に正規化してから目的の改行コードへ
const toLf = (s) => s.split("\r\n").join("\n").split("\r").join("\n");
const toCrlf = (s) => toLf(s).split("\n").join("\r\n");Python
# newline="" で読み、実際の改行コードを保ったまま扱う
with open("in.txt", newline="") as f:
body = f.read()
lf_only = body.replace("\r\n", "\n").replace("\r", "\n")コマンドライン
# CRLF → LF
dos2unix target.sh
# Git で以後の混入を防ぐ(.gitattributes)
* text=auto
*.sh text eol=lfバイト列の違い / Byte Comparison
"a" + 改行 + "b" のバイト列
CRLF (Windows) : 61 0D 0A 62 (4バイト)
LF (Unix/macOS): 61 0A 62 (3バイト)
CR (旧Mac) : 61 0D 62 (3バイト)
同じ2行のテキストでも、改行コードが違えばバイト数もハッシュ値も変わります。Why browser-only?
Files with line ending problems are usually source code, deployment scripts, or data exports — content you should not paste into an unknown server. This converter performs the replacement locally with plain string operations: nothing is uploaded, nothing is logged, and it works offline. Check the DevTools Network tab while converting — zero requests.
改行コードで困るのはソースコード・デプロイ用スクリプト・データエクスポートといった 社外に出せないファイルがほとんどです。本ツールは変換がブラウザ内で完結し、外部送信は一切ありません。