The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 03:04 AM
Routes being automatically added Conutmonky UNIX for Dummies Questions & Answers 1 02-28-2008 07:13 PM
extran NUll character added after end of line "\n" arunkumar_mca UNIX for Dummies Questions & Answers 1 11-12-2007 01:23 PM
Vi opens automatically when i login to a unix box ramky79 AIX 3 01-24-2007 11:43 PM
ftp file from Windows to Unix automatically whatisthis Shell Programming and Scripting 4 11-14-2005 02:55 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 11-28-2001
Jasmine Jasmine is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 1
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?
  #2 (permalink)  
Old 11-28-2001
jApHEth jApHEth is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 8
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
wizard wizard is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 60
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
amit amit is offline
Registered User
  
 

Join Date: Sep 2001
Posts: 12
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
doeboy doeboy is offline
Registered User
  
 

Join Date: Oct 2001
Location: Here
Posts: 137
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.
Closed Thread

Bookmarks

Tags
awk, awk trim, trim, trim awk

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0