トップ 差分 一覧 ソース 検索 ヘルプ RSS ログイン

技術的雑談-改行コード変換

改行コード変換


 環境

perlが動く環境ならまあ、どこでも。

 目的

大量のファイルの改行コードを変換したい。

 方法

perl -pe ' ';で1行スクリプトが書けますが、それと置換を組み合わせます。

基本的なことですが、
それぞれのプラットフォームの改行コードは、

UNIX : LFのみ
WIN : CR+LF
MAC : CR

という具合にばらばらです。

perlが動く環境なら簡単に改行コードを変換できます。



UNIX => Windows 

% perl -pe 's/\n/\r\n/' unixfile > winfile



UNIX => Macintosh 

% perl -pe 's/\n/\r/' unixfile > macfile



Win => UNIX 

% perl -pe 's/\r\n/\n/' winfile > unixfile



Windows => Macintosh 

% perl -pe 's/\r\n/\r/' winfile > macfile



Macintosh => UNIX 

% perl -pe 's/\r/\n/g' macfile > unixfile



Macintosh => Windows 

% perl -pe 's/\r/\r\n/g' macfile > winfile

それぞれ、
winfile、macfile、unixfileのところにそれぞれの改行コードのファイルを設定/出力します。


 履歴

2005/7/15 -- 初版

技術的雑談へ戻る

 突っ込み

name   comment  
URL (入力するとす ぱ むとみなします!)


技術的雑談へ戻る

TrackBack

TrackBack URL for this entry:
http://www.himajin2001.com/fswiki/tb.cgi/%B5%BB%BD%D1%C5%AA%BB%A8%C3%CC%2D%B2%FE%B9%D4%A5%B3%A1%BC%A5%C9%CA%D1%B4%B9

技術的雑談へ戻る

最終更新日時:最終更新時間:2005年07月15日 10時52分41秒
トップページに戻る