질문) vi 에디터 직접 열지 않고 프롬프트 ^M 없애는 방법

foruses의 이미지

도스에서 리눅스로 화일 옮길 때, 종종 ^M 자가 쭉 붙어서 나오는데요,
vi로 열어서 %s/^M//g 이렇게 보통 치환합니다.

질문은요, 화일이 하도 많고 커서, 일일이 열어보고 저장할 수가 없거든요.
프롬프트 상에서 빨리 치환하는 방법 아시는 분 도움 부탁드립니다.

랜덤여신의 이미지

perl -pi -e "s/\r//g" *

이정도면 될 것 같습니다.
다만, 한 디렉토리 내에 있는 파일만 됩니다.
하위 디렉토리까지 전부 하고 싶으시면,
find 와 결합하시면 됩니다. (사실 여기까지는 몰라요... :( )

pynoos의 이미지

머.. 간단히 하실려면..

vim -c "set ff=unix" -c "wq" a.txt

이렇게 하면 unix 포맷으로 저장하고 끝내겠죠..

find . -name "*.txt" -exec vim -c "set ff=unix" -c "wq" {} \;

이렇게 하면 .txt를 찾아서 다 바꿔줄 것이구요..

매맞는아이의 이미지

pico로 그 파일 불렀다가 저장하면 됩니다..

내가 그린 원 안에서.. 난 서 있겠지.. 언제까지나..

삶의여유의 이미지

find / -name "*.txt" -exec perl -pi -e 's/찾을문자열/바꿀문자열/g' {} ;

sed 로 하는게 정규표현식(맞나?)을 이용하는 정석인 것 같은데 그 방법은
모르겠네요. 아시는 분이 가르쳐 주시면 좋겠습니다.

liberta의 이미지

sed로는 다음처럼 하면 됩니다.

$ sed -e "s/^M//g" dos.file > unix.file

그런데, 단지 파일의 라인피드 형식만 바꾸는데는 우리의 친구 ''dos2unix''가 제일 간단하지 않을지? ^^

$ man dos2unix

송지석의 이미지

윗분 말씀처럼 dos2unix * 하시면 되겠네요.

bubicom의 이미지

bubicom@linuxstudy bin $ vi dos2unix.sh

#!/usr/bin/perl
while($fn = shift @ARGV){
print "Processing $fn";
if(open(FILE,$fn)){
$lc = 0;
$file = join('',<FILE>);
close(FILE);
$file =~ s:\r\n|\r|\n:\n:g;
open(FILE,">$fn");
print FILE $file;
close FILE;
print "\n";
} else {
print " File not found!\n";
}
}

-------------------------
모든것에 감사합니다.
http://bubicom.winmir.com

jinyeong의 이미지

$ tr -d '\r' < ori_file > new_file

로 하시면 됩니다.

ori_file 과 new_file 이름이이 같으면 안되겠지요.

뭐 굳이 같아야 하신다면 다음과 같이 하셔도..

$ cat ori_file | tr -d '\r' > ori_file

I thought what I'd do was,
I'd pretend I was one of those deaf-mutes.. or should I?

서지훈의 이미지

Quote:
Need to remove all those ^M characters from a DOS file? Try

col -bx < dosfile > newfile
-- Dru <genesis@istar.ca>

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.