LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ubuntu : delete the extra spaces (https://www.linuxquestions.org/questions/linux-newbie-8/ubuntu-delete-the-extra-spaces-822572/)

Xanios 07-28-2010 02:48 AM

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?

i92guboj 07-28-2010 03:33 AM

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).

grail 07-28-2010 03:36 AM

Well I am not sure about anyone else, but that makes absolutely no sense to me at all??
Quote:

When i deleted some lines in the config files
Which config files?
Which application were you using?
Quote:

there will be those so-called extra spaces
wtf ... either they are spaces or they aren't??
Quote:

'pull' up the lines below
In what? With what? (a hammer?? pliers?)

druuna 07-28-2010 03:37 AM

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.

Xanios 07-28-2010 04:41 AM

@i92guboj

i tried the 'Del' and 'Backspace', doesn't work.


@grail

windows.cfg for nagios

grail 07-28-2010 04:44 AM

Quote:

windows.cfg for nagios
So that is one answer. We now know which file.

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???

i92guboj 07-28-2010 04:44 AM

I assume you are opening the files in an editor. Which editor? How do you open the file?

Xanios 07-28-2010 04:50 AM

@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"

i92guboj 07-28-2010 04:59 AM

Quote:

Originally Posted by Xanios (Post 4047753)
@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"

Right, you don't "edit using sudo", you rather edit using "vi" (or "vim" most likely these days). "sudo" just grants you the necessary rights to edit that file, since it's a system file.

"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>
Nano is pretty much straightforward to use, in the fashion of traditional text editors as they've been since the DOS age. If you truly want to use vi(m) then google for vim tutorials, there are plenty.

sumeet inani 07-28-2010 06:47 AM

hey xanios
You ran
Code:

sudo vi /usr/local/nagios/etc/objects/windows.cfg
whichever line you want to delete , just position your cursor anywhere on that line (then press escape key , you will hear beep if you are already in command mode)then press 'd' twice & that line disappears while lower one jumps up.
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 ?

grail 07-28-2010 07:17 AM

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.

Xanios 07-28-2010 08:19 PM

Hey sumeet inani, thanks! It worked (: I wanna know more :) hahas.

Thanks everyone for the help too!! :D

sumeet inani 07-28-2010 11:00 PM

To learn basics of vim
You can run following command in terminal
Code:

vimtutor
Then you can see http://www.tuxfiles.org/linuxhelp/vimcheat.html for more info.
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>
There is no limit to editing tricks you can do with vim . Just you have to think. And search on internet if you get stuck.

Xanios 07-28-2010 11:15 PM

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.