ubuntu : delete the extra spaces
Hello.
I want to ask a question regarding the terminal in ubuntu. When i deleted some lines in the config files for example, there will be those so-called extra spaces left after deleting and i can't seem to delete those spaces and 'pull' up the lines below. So, how to delete those extra spaces? |
Just go to the blank line and press 'Del', or put the cursor at the beginning of the following non-empty line and press 'Backspace'.
Most editors also have other ways to do this, from the select and cut method to specific bindings to delete lines like in vi(m). |
Well I am not sure about anyone else, but that makes absolutely no sense to me at all??
Quote:
Which application were you using? Quote:
Quote:
|
Hi,
Is this what you are looking for: sed '/^$/d' infile This will remove all empty lines in a file (not if there is only a space and/or a tab), if those need to be removed too: sed '/^[[:blank:]]*$/d' infile Hope this helps. |
@i92guboj
i tried the 'Del' and 'Backspace', doesn't work. @grail windows.cfg for nagios |
Quote:
As it is a windows config file, are you doing your editing in windows or linux? Again I will ask, how are you editing, ie with what application??? |
I assume you are opening the files in an editor. Which editor? How do you open the file?
|
@grail
In linux. Hmm, with what application? Just edit it terminal using sudo? x.x @i92guboj I just open it in terminal. using "sudo vi /usr/local/nagios/etc/objects/windows.cfg" |
Quote:
"vi" clones do have two modes, a so called command mode and an edit mode. On edit mode the editor works as default in most of them (as I told you above) in command mode vi attend to special commands and it is unlikely that you will be able to handle that without some previous learning. The problem here is that by default, vi(m) will enter in command mode, so unless you know vi(m) commands you won't be able to do anything with it at all. I'd suggest you to use nano or anything else instead. I have no idea what editor might be shipped by default on your distro though. You could try nano still, it won't harm: Code:
sudo nano <whatever-file> |
hey xanios
You ran Code:
sudo vi /usr/local/nagios/etc/objects/windows.cfg Whenever you are in doubt press escape key to confirm you are in command mode. You can exit saving changes by pressing :wq or if you don't want to mess that file then :q! & whatever you did will be zero. Vi editor is great . You will be impressed with its ability once you get hang of its basics. Also there is command mode , ex mode & insert mode. Usually if you are in insert mode then you see it written on lower left corner. More on that later , if you want to know ? |
So now we have nearly all the pieces of your puzzle:
1. You are using vi(m) and the previous posts indicate how to use 2. You are attempting to edit a file, windows.cfg 3. All the above is being performed in linux So assuming that the previous posts do not work, the last question I would ask is, the file being edited, was it copied from a windows machine? This is relevant as it may well have unwanted characters at the end of lines which can cause the command mode, spoken of previously, to behave erratically. If nothing else, I hope you have gained some understanding of just what is required to ask a proper question. |
Hey sumeet inani, thanks! It worked (: I wanna know more :) hahas.
Thanks everyone for the help too!! :D |
To learn basics of vim
You can run following command in terminal Code:
vimtutor There is also a book freely available - ftp://ftp.vim.org/pub/vim/doc/book/vimbook-OPL.pdf Actually in vim each key has been assigned a function.It helped me to prepare a map linking key with its function. Also you can run in vim Code:
:help <command> |
i see. thanks lots =) there are indeed a lot of commands that i do not know of (:
|
All times are GMT -5. The time now is 10:59 PM. |