[windows] Mac에서 Windows로 줄 바꿈 형식 변환

Mac에서 생성 된 .sql 덤프 파일을 Windows에서 읽을 수있는 파일로 변환하는 변환 유틸리티 / 스크립트가 필요합니다. 이것은 내가 여기에 있었던 문제의 연속입니다 . 문제는 텍스트 파일의 줄 바꿈 형식과 관련이있는 것 같지만 변환 도구를 찾을 수 없습니다 …



답변

Windows는 개행에 carriage return+ line feed를 사용합니다 .

\r\n

유닉스는 Line feed개행 에만 사용 합니다.

\n

결론적으로 모든 발생을 \n로 대체하십시오 \r\n.
모두 unix2dosdos2unix맥 OSX에서 사용 가능한 기본으로하지 않습니다.
다행히 간단하게 Perl또는 sed작업을 수행 할 수 있습니다 .

sed -e 's/$/\r/' inputfile > outputfile                # UNIX to DOS  (adding CRs)
sed -e 's/\r$//' inputfile > outputfile                # DOS  to UNIX (removing CRs)
perl -pe 's/\r\n|\n|\r/\r\n/g' inputfile > outputfile  # Convert to DOS
perl -pe 's/\r\n|\n|\r/\n/g'   inputfile > outputfile  # Convert to UNIX
perl -pe 's/\r\n|\n|\r/\r/g'   inputfile > outputfile  # Convert to old Mac

http://en.wikipedia.org/wiki/Newline#Conversion_utilities의 코드 스 니펫


답변

이것은 Anne의 답변의 개선 된 버전입니다 .perl을 사용하면 새 파일을 생성하는 대신 ‘in-place’파일에서 편집 할 수 있습니다.

perl -pi -e 's/\r\n|\n|\r/\r\n/g' file-to-convert  # Convert to DOS
perl -pi -e 's/\r\n|\n|\r/\n/g'   file-to-convert  # Convert to UNIX


답변

Homebrew로 unix2dos를 설치할 수 있습니다

brew install unix2dos

그런 다음이 작업을 수행 할 수 있습니다

unix2dos file-to-convert

dos 파일을 유닉스로 변환 할 수도 있습니다 :

dos2unix file-to-convert


답변

아마도 unix2dos를 원할 것입니다 :

$ man unix2dos

NAME
       dos2unix - DOS/MAC to UNIX and vice versa text file format converter

SYNOPSIS
           dos2unix [options] [-c CONVMODE] [-o FILE ...] [-n INFILE OUTFILE ...]
           unix2dos [options] [-c CONVMODE] [-o FILE ...] [-n INFILE OUTFILE ...]

DESCRIPTION
       The Dos2unix package includes utilities "dos2unix" and "unix2dos" to convert plain text files in DOS or MAC format to UNIX format and vice versa.  Binary files and non-
       regular files, such as soft links, are automatically skipped, unless conversion is forced.

       Dos2unix has a few conversion modes similar to dos2unix under SunOS/Solaris.

       In DOS/Windows text files line endings exist out of a combination of two characters: a Carriage Return (CR) followed by a Line Feed (LF).  In Unix text files line
       endings exists out of a single Newline character which is equal to a DOS Line Feed (LF) character.  In Mac text files, prior to Mac OS X, line endings exist out of a
       single Carriage Return character. Mac OS X is Unix based and has the same line endings as Unix.

cygwin을unix2dos 사용하는 DOS / Windows 시스템 또는 MacPorts를 사용하는 Mac에서 실행할 수 있습니다 .


답변

그냥 tr삭제하십시오 :

tr -d "\r" <infile.txt >outfile.txt


답변

  1. Homebrew와 함께 dos2unix 설치
  2. find ./ -type f -exec dos2unix {} \;현재 폴더 내의 모든 줄 끝을 재귀 적으로 변환하기 위해 실행

답변

vimUNIX에서 DOS 형식으로 파일을 변환 할 수도 있습니다. 예를 들면 다음과 같습니다.

vim hello.txt <<EOF
:set fileformat=dos
:wq
EOF