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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-31-2005, 07:18 AM
|
#1
|
LQ Newbie
Registered: Aug 2004
Location: pittsburgh!
Distribution: fc10
Posts: 28
Rep:
|
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
|
|
|
01-31-2005, 07:36 AM
|
#2
|
LQ Guru
Registered: Jan 2001
Posts: 24,149
|
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.
|
|
|
01-31-2005, 07:39 AM
|
#3
|
Member
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388
Rep:
|
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").
|
|
|
01-31-2005, 07:43 AM
|
#4
|
LQ Newbie
Registered: Aug 2004
Location: pittsburgh!
Distribution: fc10
Posts: 28
Original Poster
Rep:
|
that is so sweet dude, you have made my day
regards,
travis
|
|
|
01-31-2005, 07:56 AM
|
#5
|
Senior Member
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783
Rep:
|
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.
|
|
|
01-31-2005, 08:07 AM
|
#6
|
LQ Guru
Registered: Jan 2001
Posts: 24,149
|
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.
|
|
|
01-31-2005, 08:21 AM
|
#7
|
Senior Member
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783
Rep:
|
thanx...
I'll try that
|
|
|
All times are GMT -5. The time now is 10:47 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|