How to delete large portions of text on linux scripting?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
How to delete large portions of text on linux scripting?
Hi guys,
I have created a linux program using #!/bin/sh, but later I found out that I don't need around 2/3 of my program.
My program is quite long, and I need to delete around 500 lines or so in total. Now, I don't want to use "backspace" to delete that many lines, so could someone please tell me how to delete many lines at once? (for example, in microsoft word you would have to highlight the text with your mouse and press delete.)
You could open the text in vim and delete it as follows:
- Press Esc to make sure you're in the command mode
- press: 100dd
It will delete 100 lines starting from the current line going downwards. You can repeat the command using a dot (.) or type it again. As always, make sure you have a backup before you start experimenting with it.
We probably posted it at the same time but well... you posted it from Windows.... I did it from Slackware and as we all know, Slackware trumps everything (or not to start distro wars, it definitely trumps Windows). LOL
Last edited by sycamorex; 08-14-2013 at 12:36 PM.
Reason: s/disto/distro/
If you're not worried about street cred, vim's visual mode makes this much easier since you won't have to count lines before starting.
- Press Esc to make sure you're in the command mode
- Navigate to beginning of text to be deleted
- Press v to enter visual mode (you'll see --VISUAL-- at the bottom of screen)
- Navigate to end of text to be deleted
- Press d
You can even navigate with arrow keys or pgup/pgdown (gasp!)
If you're not worried about street cred, vim's visual mode makes this much easier since you won't have to count lines before starting.
- Press Esc to make sure you're in the command mode
- Navigate to beginning of text to be deleted
- Press v to enter visual mode (you'll see --VISUAL-- at the bottom of screen)
- Navigate to end of text to be deleted
- Press d
You can even navigate with arrow keys or pgup/pgdown (gasp!)
Abomination!
Last edited by szboardstretcher; 08-14-2013 at 01:04 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.