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.) Thanks! P.S. I am using Cygwin. |
Hi and welcome to LQ.
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. |
Edit:
Sycamorex and I posted the same answer at the same time. |
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
|
I agree. That's why im posting this from Lynx in Scientific Linux to get some street cred back.
If you know the lines numbers and you have sed, then you could delete the lines like this: Code:
sed -i '100,600d' file.txt |
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!) |
Quote:
|
What is this 'VISUAL' of which you speak? ;) :)
|
1 Attachment(s)
Maybe he means:
|
All times are GMT -5. The time now is 11:36 PM. |