LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-31-2005, 07:18 AM   #1
sefzik
LQ Newbie
 
Registered: Aug 2004
Location: pittsburgh!
Distribution: fc10
Posts: 28

Rep: Reputation: 15
return in text files


i have a strange sort of question for the brains out there

often when i create text files strange things happen to me
for example, i create a text file under windows, i then transfer it over to my linux system and when i open up the file with vi (using the binary, -b, flag) i have a bunch of margin returns at the end of each line ( ^M ) which many unix programs ignore and the file is thus read as one long line

i usually open the file as such, vi {file} -b
and it shows ^M at the end of everyline
i then go and delete each, which takes way too long

has anybody ever experienced this and if so, are there any shortcuts that i can use (like a find and delete command)?


thanks,
travis
 
Old 01-31-2005, 07:36 AM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
That's the crappy microsoft formatting in text files your seeing.

In vi there is an easy way to remove them all without having to do it manually..

In command mode (ESC) do this:

:1,$ s/^M//g

To make the ^M do a ctrl-V and them ctrl-M.
 
Old 01-31-2005, 07:39 AM   #3
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
Ah yes, the fun of newlines

To convert a file from Windows to Linux style end of lines, then I think the command you want is dos2unix.

Alternatively, there are several Windows text editors that can save with the correct end of line characters, avoiding the problem in the first place. I find Crimson Editor is very good (and free!) http://www.crimsoneditor.com/

(In the "Document" menu, choose "File Format", then "UNIX format").
 
Old 01-31-2005, 07:43 AM   #4
sefzik
LQ Newbie
 
Registered: Aug 2004
Location: pittsburgh!
Distribution: fc10
Posts: 28

Original Poster
Rep: Reputation: 15
that is so sweet dude, you have made my day

regards,
travis
 
Old 01-31-2005, 07:56 AM   #5
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
Quote:
has anybody ever experienced this and if so, are there any shortcuts that i can use (like a find and delete command)?
Well for linux/unix new line is one character '/n'. For windows new line are two characters /r/n. Return and then new line. I think for Apple the new line is /r and Microsoft combined those two approaches. If you open it without -b option it should be displayed well. I think this is why people say never to edit linux system files in windows. Newbies who cannot use vi if they have a problem with gui and have the tendency to copy system files and alter them in windows. There are many ways delete those character. Some year ago i wrote a lilltle C program to do that, but you may use tr or sed or even trickykid's way ( i don't know, i'm not a vi guru).

But, since you solved the problem, i'll hijack your thread
I always had this problem with vi (not vim, lets say elvis, the standard slackware vi-clone).

when you have a text:
dgfgddg
fgdgdfgfd
gdgdgfgg

how do you delete the new line char. If i want to delete the second line i alway end up to something like this:
dgfgddg

gdgdgfgg

and i don't know how to make it look like this:
dgfgddg
gdgdgfgg

Last edited by perfect_circle; 01-31-2005 at 08:00 AM.
 
Old 01-31-2005, 08:07 AM   #6
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally posted by perfect_circle
I always had this problem with vi (not vim, lets say elvis, the standard slackware vi-clone).

when you have a text:
dgfgddg
fgdgdfgfd
gdgdgfgg

how do you delete the new line char. If i want to delete the second line i alway end up to something like this:
dgfgddg

gdgdgfgg

and i don't know how to make it look like this:
dgfgddg
gdgdgfgg
I just use dd on the line I want to delete and it will remove the whole line.

So if you had:

dgfgddg
fgdgdfgfd
gdgdgfgg

And wanted that middle line deleted so it looks like this:

dgfgddg
gdgdgfgg

Place the cursor on that line and simply type dd in command mode. It'll snap it right outta there, as this would be the easiest way of doing it.
 
Old 01-31-2005, 08:21 AM   #7
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
thanx...
I'll try that
 
  


Reply



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
Convert DOS text files to UNIX text files ta0kira Linux - Software 7 03-15-2011 11:42 AM
Convert text files to html files lothario Linux - Software 3 09-27-2005 08:48 PM
How to return to text mode from x Windows fossil80 Linux - Newbie 4 07-31-2003 02:00 AM
php - find files (photo*.jpg) and return results to an array omarswan Programming 2 06-20-2003 11:42 AM
How to return text mode vinhhv Linux - Newbie 3 08-25-2002 03:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:05 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration