How can I search and replace linefeeds interactively?
Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
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.
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.
If by "linebreak" you mean the line feed that's at the end of every line, just go to the line whose ending line feed you want to eliminate, and use the J command (upper case jay) to combine that line with the next line.
On the other hand, if by "linebreak" you mean a line that contains no characters, you can search for such a line by searching for
Code:
^$
If you want to delete that blank line, make sure you're still on that line, and use the same J command. Then use the n command (lower case en) to go to the next empty line.
Rinse. Repeat.
If you're new to vi, google for
Code:
vi tutorial
You'll get a wealth of information.
Hope this helps.
Last edited by wjevans_7d1@yahoo.co; 03-19-2007 at 01:06 AM.
If by "linebreak" you mean the line feed that's at the end of every line, just go to the line whose ending line feed you want to eliminate, and use the J command (upper case jay) to combine that line with the next line.
...
Hope this helps.
Now you'r teasing - almost 30 years ago I was officially introduced to vi - and I proved to be virtually immune to this.
The idea was to to be able to quickly remove a lot of linefeed characters from a long piece of text.
Most often you would want to remove all but the double ones denoting paragraph breaks. This is a task that is often needed when for instance you receive som text on email and want to include it some other place where the length of the lines don't fit.
It is much much faster to use a search and replace function than to manually navigate around and delete.
I found out that you can do this in editpad, which is developed for windows, but there is a linux version. There you can copy a linefeed, paste it into the search box and then rush through the text replacing and skipping as needed.
Thanks - a really good tutorial - starting from the beginning - the thing with newlines comes at the very end of part 3, which I don't see any links to, but changing the numbers in the web address did the trick. Also very useful - though I don't see that it is possible to use it interactively
My vim seems debile though. Entering the suggested command does start an interactive replace function, with this:
replace with replaceword (y/n/a/q/l/^E/^Y)
in the bottom. But it only accepts y for an answer (pretty clever, hu). Other answers makes nothing happen - it doesn't continue with other answers but y and a, which have the same effenct as y. As a bit of consolation it only replaces every second newline in the file (every time you run it).
It looked promising, but something is rotten here.
I also tried the GUI version, this also have the function in the GUI and it accepts \n as a newline search and it does highlight all the newlines in the file, but it cannot delete or replace them. This is version 7.0.30
That's because vi/vim is a really powerful editor - you can get a lot done and very quickly. A friend of mine uses nothing BUT vim to edit text and he can edit stuff way faster than I can in any other text editor (command line or not). It's not a difference in typing speed or anything like that, it's just that vim is that versatile and will allow you to get more done.
In fact, where I go to school you are not allowed to use anything other than vim or emacs as a text editor. There's a reason for that
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.