LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices

Reply
 
Search this Thread
Old 12-28-2004, 04:09 PM   #1
lel800
Member
 
Registered: Aug 2003
Distribution: Red Hat RHEL WS 3, RHEL WS 4
Posts: 228

Rep: Reputation: 30
Wierd String appended to end of line


I opened up a file in vi and at the end of each line I could see the following characters...
"^M". I can surely say I did not type them there. I also see the characters when I view the file in emacs, but not when I view it in gedit. What could cause these characters to appear? If anyone has any ideas I'd love to know. Thanks.
 
Old 12-28-2004, 04:17 PM   #2
SeT
Member
 
Registered: Dec 2002
Location: cincinnati
Posts: 87

Rep: Reputation: 15
that's pretty common of a file that was created in windows. can be corrected by:

cat originalfile | tr -d \\015 >> newfile
 
Old 12-28-2004, 04:29 PM   #3
Brain Drop
Member
 
Registered: Feb 2003
Location: just outside reality
Distribution: balanced
Posts: 752

Rep: Reputation: 35
This also happens to me when I make a script file to print a hard copy of my homework for turn in. Then it can't print it because of those characters. Another way to get rid of it in vi is:
Code:
:1,$ s/<ctrl>vm//g
 
Old 12-28-2004, 04:31 PM   #4
lel800
Member
 
Registered: Aug 2003
Distribution: Red Hat RHEL WS 3, RHEL WS 4
Posts: 228

Original Poster
Rep: Reputation: 30
That worked !! Awesome !! Thanks so much )

Can you explain that line of code a bit...

Thanks ever so much
 
Old 12-28-2004, 04:32 PM   #5
lel800
Member
 
Registered: Aug 2003
Distribution: Red Hat RHEL WS 3, RHEL WS 4
Posts: 228

Original Poster
Rep: Reputation: 30
My smiley is a bit wierd....

)

should be

 
Old 12-28-2004, 04:33 PM   #6
lel800
Member
 
Registered: Aug 2003
Distribution: Red Hat RHEL WS 3, RHEL WS 4
Posts: 228

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by SeT
that's pretty common of a file that was created in windows. can be corrected by:

cat originalfile | tr -d \\015 >> newfile
This was what I used....

I'll take a look at that method for vi...Thanks for your post..
 
Old 12-28-2004, 04:48 PM   #7
lel800
Member
 
Registered: Aug 2003
Distribution: Red Hat RHEL WS 3, RHEL WS 4
Posts: 228

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by SeT
that's pretty common of a file that was created in windows. can be corrected by:

cat originalfile | tr -d \\015 >> newfile
I understand most of this...I think...

"cat" will concatenate or simply output the file to the standard output, but here it is piped into the "tr" command which will translate or delete characters. In this case the "-d" option or delete option is specified so the characters will be deleted .. and then this ">>" sends the output to a new file with the given name.

But how did you know to use "\\015" as the equivalent of "^M" ?

Thanks again.
 
Old 12-28-2004, 04:49 PM   #8
SeT
Member
 
Registered: Dec 2002
Location: cincinnati
Posts: 87

Rep: Reputation: 15
"cat originalfile" reads from the file where you still have the "^M" characters. the "|" redirects the output of the cat to the "tr -d \\015" tr is the translate command, the -d option is saying to delete a character, specifically, the \\015 char... I used to have a site that told a lot of the more usefull character codes but have lost it.
 
Old 12-28-2004, 04:55 PM   #9
Brain Drop
Member
 
Registered: Feb 2003
Location: just outside reality
Distribution: balanced
Posts: 752

Rep: Reputation: 35
I like that way. This is the type of thing I want to learn more of.
And just in case you want an explanation of my method:

':' to enter commands in vi '1,$' from begining to end of a line 's' substitute /this/ with this/ and 'g' do it globally. I think.

Last edited by Brain Drop; 12-28-2004 at 04:57 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C: fread to read a file line by line until the end Blue_muppet Programming 2 09-19-2008 10:42 AM
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 09:22 AM
batch append string to the end of a determined line in text files osio Programming 6 06-30-2005 10:28 AM
How to get rid of the begining and end space of a string for PERL?? cqmyg5 Slackware 2 04-28-2005 05:34 PM
/r at end of line in script silence Linux - General 1 08-21-2004 09:25 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration