LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-28-2010, 03:48 AM   #1
Xanios
Member
 
Registered: Jul 2010
Posts: 216

Rep: Reputation: 30
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?
 
Old 07-28-2010, 04:33 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
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).
 
Old 07-28-2010, 04:36 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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?)
 
Old 07-28-2010, 04:37 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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.
 
Old 07-28-2010, 05:41 AM   #5
Xanios
Member
 
Registered: Jul 2010
Posts: 216

Original Poster
Rep: Reputation: 30
@i92guboj

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


@grail

windows.cfg for nagios
 
Old 07-28-2010, 05:44 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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???
 
Old 07-28-2010, 05:44 AM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
I assume you are opening the files in an editor. Which editor? How do you open the file?
 
Old 07-28-2010, 05:50 AM   #8
Xanios
Member
 
Registered: Jul 2010
Posts: 216

Original Poster
Rep: Reputation: 30
@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"
 
Old 07-28-2010, 05:59 AM   #9
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by Xanios View Post
@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.
 
Old 07-28-2010, 07:47 AM   #10
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Rep: Reputation: 48
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 ?

Last edited by sumeet inani; 07-28-2010 at 07:50 AM.
 
Old 07-28-2010, 08:17 AM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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.
 
Old 07-28-2010, 09:19 PM   #12
Xanios
Member
 
Registered: Jul 2010
Posts: 216

Original Poster
Rep: Reputation: 30
Hey sumeet inani, thanks! It worked (: I wanna know more hahas.

Thanks everyone for the help too!!
 
Old 07-29-2010, 12:00 AM   #13
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Rep: Reputation: 48
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.
 
Old 07-29-2010, 12:15 AM   #14
Xanios
Member
 
Registered: Jul 2010
Posts: 216

Original Poster
Rep: Reputation: 30
i see. thanks lots =) there are indeed a lot of commands that i do not know of (:
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
howto delete extra kernel lists at boot of Mandriva 2010 islay04 Linux - Newbie 11 05-15-2010 10:55 AM
kwrite - how to delete spaces adrian2009 Linux - Software 1 06-13-2009 12:35 PM
[SOLVED] Remove extra spaces in a line vikas027 Programming 11 10-11-2008 09:20 AM
To delete extra options thexy Linux - Newbie 4 02-09-2005 12:28 PM
Html: Extra Spaces on Top mikeshn Programming 1 07-05-2003 04:40 PM


All times are GMT -5. The time now is 05:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration