f



Command for converting text file (Windows CR) to text file (Linux) ?

Assume I trasferred/uploaded a text file (which was created on a Win system) to Linux system.

How can I convert the eol chars to the Linux style ?

I opened (and later saved) it in vi editor. But this didn't help.

What else can I do to convert it?

Karl
0
k
12/11/2007 8:34:49 PM
comp.unix.shell 15484 articles. 2 followers. Post Follow

16 Replies
2119 Views

Similar Articles

[PageSpeed] 47

In article <475ef469$0$17522$9b4e6d93@newsspool4.arcor-online.net>,
Karl Medrell <k.medrell@hotmail.com> wrote:
>Assume I trasferred/uploaded a text file (which was created on a Win
>system) to Linux system.
>
>How can I convert the eol chars to the Linux style ?
>
>I opened (and later saved) it in vi editor. But this didn't help.
>
>What else can I do to convert it?
>
>Karl

Given what you've done so far, and assuming this is a "one-shot" deal on
one particular file and that you are using "vim" as "vi" under Linux,
the easiest thing to do is to do: "set ff=unix" before (re-)saving the file.

1
gazelle2 (1307)
12/11/2007 8:39:25 PM
Karl Medrell wrote:

> Assume I trasferred/uploaded a text file (which was created on a Win
> system) to Linux system.
> How can I convert the eol chars to the Linux style ?
> I opened (and later saved) it in vi editor. But this didn't help.
> What else can I do to convert it?
> Karl

Google yields some rather promising looking results using "convert text file
line endings".

-- 
Larry Bristol --- The Double Luck
http://www.doubleluck.com

0
larry8974 (16)
12/11/2007 8:45:17 PM
On Dec 11, 3:34 pm, k.medr...@hotmail.com (Karl Medrell) wrote:
> Assume I trasferred/uploaded a text file (which was created on a Win system) to Linux system.
>
> How can I convert the eol chars to the Linux style ?
>
> I opened (and later saved) it in vi editor. But this didn't help.
>
> What else can I do to convert it?
>
> Karl

in vi, substitute CtrM at eol w/ null.  keystrokes are

:/s/CtrlVCtrlM$//g

if the file is ftp'd in ascii mode from windows to linux, or the other
way around, the correct conversion is applied for you
0
12/11/2007 8:45:31 PM
In comp.os.linux.misc Karl Medrell <k.medrell@hotmail.com> wrote:
> Assume I trasferred/uploaded a text file (which was created on a Win system) to Linux system.
> 
> How can I convert the eol chars to the Linux style ?
> 
> I opened (and later saved) it in vi editor. But this didn't help.
> 
> What else can I do to convert it?
> 
> Karl

win2unix ( and the opposite unix2win ) work just fine. There are
various other solutions to handle the EOL issue between the three
worlds ( Windows/unix/Mac )

do a quick search and you'll find source and/or executables
in a number of places. Note that you can do the conversion
on any of the platforms- whatever works best for you.

Stan
-- 
Stan Bischof ("stan" at the below domain)
www.worldbadminton.com 
0
stan38 (496)
12/11/2007 8:49:05 PM
On 2007-12-11, Karl Medrell wrote:
>

> Assume I trasferred/uploaded a text file (which was created on a Win
> system) to Linux system.
> How can I convert the eol chars to the Linux style ?
>
> I opened (and later saved) it in vi editor. But this didn't help.
>
> What else can I do to convert it?

   Most systems have a dos2unix command. If you don't have that, you
   can use sed:

sed "s/\r$//" FILE

-- 
   Chris F.A. Johnson, author       <http://cfaj.freeshell.org/shell/>
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   ===== My code in this post, if any, assumes the POSIX locale
   ===== and is released under the GNU General Public Licence
0
Chris
12/11/2007 9:11:09 PM
On 11 Dec 2007 20:34:49 GMT, k.medrell@hotmail.com (Karl Medrell)
wrote:

>Assume I trasferred/uploaded a text file (which was created on a Win system) to Linux system.
>
>How can I convert the eol chars to the Linux style ?
>
>I opened (and later saved) it in vi editor. But this didn't help.
>
>What else can I do to convert it?
>
>Karl


man fromdos 
man dos2unix


Scott McMillan
0
smcmillan (35)
12/11/2007 9:17:50 PM
On 2007-12-11, Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
> On 2007-12-11, Karl Medrell wrote:
>>
>
>> Assume I trasferred/uploaded a text file (which was created on a Win
>> system) to Linux system.
>> How can I convert the eol chars to the Linux style ?
>>
>> I opened (and later saved) it in vi editor. But this didn't help.
>>
>> What else can I do to convert it?
>
>    Most systems have a dos2unix command. If you don't have that, you
>    can use sed:
>
> sed "s/\r$//" FILE

or 

tr -d '\r' <oldfile >newfile


-- 
Grant Edwards                   grante             Yow! I'm wearing PAMPERS!!
                                  at               
                               visi.com            
0
Grant
12/11/2007 10:19:53 PM
At 11 Dec 2007 20:34:49 GMT k.medrell@hotmail.com (Karl Medrell) wrote:

> 
> Assume I trasferred/uploaded a text file (which was created on a Win system) to Linux system.
> 
> How can I convert the eol chars to the Linux style ?
> 
> I opened (and later saved) it in vi editor. But this didn't help.
> 
> What else can I do to convert it?

tr -d '\r' <MS-DOSFILE >UNIXFile

man tr

(also: 

 tr '\r' '\n' <MACOSFILE >UNIXFILE
)



> 
> Karl
>                  

-- 
Robert Heller             -- Get the Deepwoods Software FireFox Toolbar!
Deepwoods Software        -- Linux Installation and Administration
http://www.deepsoft.com/  -- Web Hosting, with CGI and Database
heller@deepsoft.com       -- Contract Programming: C/C++, Tcl/Tk
                             
0
Robert
12/11/2007 10:54:06 PM
Larry Bristol <larry@doubleluck.com> did eloquently scribble:
> Karl Medrell wrote:

>> Assume I trasferred/uploaded a text file (which was created on a Win
>> system) to Linux system.
>> How can I convert the eol chars to the Linux style ?
>> I opened (and later saved) it in vi editor. But this didn't help.
>> What else can I do to convert it?
>> Karl

> Google yields some rather promising looking results using "convert text file
> line endings".

The common ones are probably already installed on the system on linux.
(and the bsds)
dos2unix and unix2dos

-- 
______________________________________________________________________________
|   spike1@freenet.co.uk   | "I'm alive!!! I can touch! I can taste!         |
|Andrew Halliwell BSc(hons)|  I can SMELL!!!  KRYTEN!!! Unpack Rachel and    |
|            in            |  get out the puncture repair kit!"              |
|     Computer Science     |     Arnold Judas Rimmer- Red Dwarf              |
------------------------------------------------------------------------------
0
spike1 (8171)
12/12/2007 12:36:31 AM
On 11 Dez., 21:34, k.medr...@hotmail.com (Karl Medrell) wrote:
> Assume I trasferred/uploaded a text file (which was created on a Win system) to Linux system.
>
> How can I convert the eol chars to the Linux style ?
>
> I opened (and later saved) it in vi editor. But this didn't help.
>
> What else can I do to convert it?

Besides the external tools you have been suggested already...

If it's just a single file you can remove the characters while in vi;

  :s/.$//

....removes the last character (CR, ^M) before the newline (NL),

  :s/^M$//

....removes the CR characters (where ^M is types as <Ctrl-M>), or

  :set notextmode
  :w

the latter if you're using vim.

Janis

>
> Karl

0
12/12/2007 8:53:30 AM
At 2007-12-11 05:19PM, "Grant Edwards" wrote:
>  On 2007-12-11, Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
> >    Most systems have a dos2unix command. If you don't have that, you
> >    can use sed:
> >
> > sed "s/\r$//" FILE
>  
>  or 
>  
>  tr -d '\r' <oldfile >newfile

That's overly ambitious.  It will remove carriage returns that
are not at the end of the line -- in which case, they're probably there
on purpose.
    

-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
0
Glenn
12/12/2007 3:48:54 PM
At 2007-12-11 03:34PM, "Karl Medrell" wrote:
>  Assume I trasferred/uploaded a text file (which was created on a Win system) to Linux system.
>  
>  How can I convert the eol chars to the Linux style ?
>  
>  I opened (and later saved) it in vi editor. But this didn't help.

In addition to the other answers (dos2unix and sed), if you're using vim:
    :set ff=unix
    :w

-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
0
glennj (645)
12/12/2007 3:51:48 PM
On Dec 11, 3:34 pm, k.medr...@hotmail.com (Karl Medrell) wrote:
> Assume I trasferred/uploaded a text file (which was created on a Win system) to Linux system.
>
> How can I convert the eol chars to the Linux style ?
>
> I opened (and later saved) it in vi editor. But this didn't help.
>
> What else can I do to convert it?
>
> Karl

http://www.vim.org/tips/tip.php?tip_id=26

:%s/^M//g

to get ^M, type CTRL+V and then CTRL+M. Do not type SHIFT+6 and SHIFT
+M......read the about link it says it all

-RB
0
rachit7 (5)
12/12/2007 8:34:04 PM
On 2007-12-11, Robert Heller <heller@deepsoft.com> wrote:
>> Assume I trasferred/uploaded a text file (which was created on a Win system) to Linux system.
>> How can I convert the eol chars to the Linux style ?
>> I opened (and later saved) it in vi editor. But this didn't help.
>> What else can I do to convert it?
>
> tr -d '\r' <MS-DOSFILE >UNIXFile
> man tr
> (also: 
>  tr '\r' '\n' <MACOSFILE >UNIXFILE
> )

Also, in a lot of Linux distro's: dos2unix.

-- 
There is an art, it says, or rather, a knack to flying.
The knack lies in learning how to throw yourself at the ground and miss.
Douglas Adams
0
Rikishi
12/13/2007 12:13:34 AM
k.medrell@hotmail.com (Karl Medrell) writes:

> How can I convert the eol chars to the Linux style ?
> 
> I opened (and later saved) it in vi editor. But this didn't help.

AFAIK - You have to modify the file. Otherwise - vi will not save
changes.  I typically insert then delete a single character.
0
nospam63 (611)
12/14/2007 3:45:22 PM
On Tue, 11 Dec 2007 20:34:49 +0000, Karl Medrell wrote:

> Assume I trasferred/uploaded a text file (which was created on a Win
> system) to Linux system.
> 
> How can I convert the eol chars to the Linux style ?
> 
> I opened (and later saved) it in vi editor. But this didn't help.
> 
> What else can I do to convert it?
> 
> Karl

Add this to your .xemacs/init.el file and then open it in Xemacs.


(add-hook 'find-file-hooks 'remove-or-convert-trailing-ctl-M)
(defun remove-or-convert-trailing-ctl-M ()
  "Propose to remove or convert trailing ^M from a file."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (if (search-forward "\^M" nil t)
        ;: a ^M is found
        (if (or (= (preceding-char) ?\^J)
                (= (following-char) ?\^J) )
            ;: Must find a way to display the buffer before this question
            (if (y-or-n-p "Remove trailing ^M ? ")
                (progn (goto-char (point-min))
                       (perform-replace "\^M" "" nil nil nil)
                       (pop-mark) )
              (message "No transformation.") )
          (if (y-or-n-p "Convert ^M into ^J ? ")
              (progn (goto-char (point-min))
                     (perform-replace "\^M" "\^J" nil nil nil)
                     (pop-mark) )
            (message "No transformation.") ) )
      ;:(message "No ^M in this file !")
      )
    ))
0
schvantzkopf (307)
12/14/2007 4:06:05 PM
Reply: