The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to send mail automatically in unix rajan_ka1 Shell Programming and Scripting 7 05-30-2008 12:04 AM
Routes being automatically added Conutmonky UNIX for Dummies Questions & Answers 1 02-28-2008 03:13 PM
extran NUll character added after end of line "\n" arunkumar_mca UNIX for Dummies Questions & Answers 1 11-12-2007 09:23 AM
Vi opens automatically when i login to a unix box ramky79 AIX 3 01-24-2007 07:43 PM
ftp file from Windows to Unix automatically whatisthis Shell Programming and Scripting 4 11-14-2005 10:55 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-28-2001
Registered User
 

Join Date: Nov 2001
Posts: 1
Stumble this Post!
Question there was a strange character(^M) been added automatically in UNIX

I used Notepad to compile my txt file and then I transferred this file to UNIX. When I use vi to open the file, I found that at the end of each line there was a "^M" character.
In the original txt file there was not this character. Why this character would been added automatically in UNIX?
Forum Sponsor
  #2 (permalink)  
Old 11-28-2001
Registered User
 

Join Date: Nov 2001
Posts: 8
Stumble this Post!
the text file under unix is fifferent from m$ DOS,

if you use ftp to exchange text files between them, you should always use ascii model;
if you use mcopy u should always add the -t switch

or you may use this to trim the '^M' charater under unix if you already cp'ed the text file to unix:
tr -d "\015" < hello.c > hello.unix.c
  #3 (permalink)  
Old 11-28-2001
Registered User
 

Join Date: Nov 2001
Posts: 60
Stumble this Post!
You could also do a global replace in vi. At the command prompt
(the , type

1,$s/ctrl-vm//g

where ctrl-v means hold the control key while pressing the letter v. Then release them both and press the m key. The text at the command prompt should then look like

1,$s/^M//g

This will strip the ^M which is a linefeed in DOS/Windows. Next time you should do as jApHEth said and ftp in ASCII mode.
  #4 (permalink)  
Old 11-29-2001
Registered User
 

Join Date: Sep 2001
Posts: 12
Stumble this Post!
In DOS ,the end of the line is indiacted by two characters to have compatability with type writer i.e enter ( new line feed) and carrige return (to bring the typewriter head to start position) but in unix only end of line is there with no carrige return so character
' ^ M ' gets appended at the end of line.
  #5 (permalink)  
Old 11-30-2001
doeboy's Avatar
Registered User
 

Join Date: Oct 2001
Location: Here
Posts: 137
Stumble this Post!
You could use the dos2unix command to take the ^M characters out.

do something like this:

dos2unix file &gt; newfile

This will create a new file that is the same as your original file except without the ^M characters.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0