Quantcast

HowTo delete all lines ending in a certain string?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

HowTo delete all lines ending in a certain string?

Chris Hudson-2
Hi, I have a question.  I have a very big directory/subdirectory listing that has been outputted to a file.
I would like to delete all the dot ( . ) and dot-dot ( .. ) directories, so that I just have a listing of the "real" directories. 
 
So I want to delete all lines that look like this: 
 

drwxrwx--- 2 odevora dba 4096 Feb 21 15:41 .

drwxrwx--- 4 odevora dba 4096 Oct 2 2009 ..

 

 And leave all the other lines, such as this:
 

drwxrwx--- 2 odevora dba 4096 Feb 21 15:41 bin

drwxrwx--- 2 odevora dba 110592 Mar 8 21:07 log

 
 
Thanks,
Chris
 

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: HowTo delete all lines ending in a certain string?

Horvath Adam-2
Hi Chris!

Generally:
:g/pattern/d

Specific for you (delete all line ending with '.' char):
:g/\.$/d


Adam



2011/3/10 Chris Hudson <[hidden email]>:

> Hi, I have a question.  I have a very big directory/subdirectory listing
> that has been outputted to a file.
> I would like to delete all the dot ( . ) and dot-dot ( .. ) directories, so
> that I just have a listing of the "real" directories.
>
> So I want to delete all lines that look like this:
>
>
> drwxrwx--- 2 odevora dba 4096 Feb 21 15:41 .
>
> drwxrwx--- 4 odevora dba 4096 Oct 2 2009 ..
>
>
>
>  And leave all the other lines, such as this:
>
>
> drwxrwx--- 2 odevora dba 4096 Feb 21 15:41 bin
>
> drwxrwx--- 2 odevora dba 110592 Mar 8 21:07 log
>
>
>
> Thanks,
> Chris
>
>
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: HowTo delete all lines ending in a certain string?

Christian Brabandt
In reply to this post by Chris Hudson-2
On Thu, March 10, 2011 3:17 pm, Chris Hudson wrote:

> Hi, I have a question.  I have a very big directory/subdirectory listing
> that has been outputted to a file.
> I would like to delete all the dot ( . ) and dot-dot ( .. ) directories,
> so
> that I just have a listing of the "real" directories.
>
> So I want to delete all lines that look like this:
>
>
> drwxrwx--- 2 odevora dba 4096 Feb 21 15:41 .
>
> drwxrwx--- 4 odevora dba 4096 Oct 2 2009 ..
>
>
>  And leave all the other lines, such as this:
>
>
> drwxrwx--- 2 odevora dba 4096 Feb 21 15:41 bin
>
> drwxrwx--- 2 odevora dba 110592 Mar 8 21:07 log
>

:g/\.\.\?$/d

:h :g

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: HowTo delete all lines ending in a certain string?

Chris Hudson-2
Thanks for the replies, that did the trick.
 
 --Chris


 
On Thu, Mar 10, 2011 at 9:20 AM, Christian Brabandt <[hidden email]> wrote:
On Thu, March 10, 2011 3:17 pm, Chris Hudson wrote:
> Hi, I have a question.  I have a very big directory/subdirectory listing
> that has been outputted to a file.
> I would like to delete all the dot ( . ) and dot-dot ( .. ) directories,
> so
> that I just have a listing of the "real" directories.
>
> So I want to delete all lines that look like this:
>
>
> drwxrwx--- 2 odevora dba 4096 Feb 21 15:41 .
>
> drwxrwx--- 4 odevora dba 4096 Oct 2 2009 ..
>
>
>  And leave all the other lines, such as this:
>
>
> drwxrwx--- 2 odevora dba 4096 Feb 21 15:41 bin
>
> drwxrwx--- 2 odevora dba 110592 Mar 8 21:07 log
>

:g/\.\.\?$/d

:h :g

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: HowTo delete all lines ending in a certain string?

Gene Kwiecinski
In reply to this post by Chris Hudson-2
>Hi, I have a question.  I have a very big directory/subdirectory listing
>that has been outputted to a file.
>I would like to delete all the dot ( . ) and dot-dot ( .. ) directories,
>so that I just have a listing of the "real" directories.

Ummm, use 'ls -A' instead of 'ls -a'?

Just seems easier to me...  :D


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: HowTo delete all lines ending in a certain string?

Michael(Xi Zhang)
On Thu, Mar 10, 2011 at 3:49 PM, Gene Kwiecinski <[hidden email]> wrote:
>Hi, I have a question.  I have a very big directory/subdirectory listing
>that has been outputted to a file.
>I would like to delete all the dot ( . ) and dot-dot ( .. ) directories,
>so that I just have a listing of the "real" directories.

Ummm, use 'ls -A' instead of 'ls -a'?

Just seems easier to me...  :D

You mean delete directories line end with . or .. ?
If yes, you can try this command
:%s/\.\{1,2}\s*$//
This will delete . or .. end of line.

Check out:
:h :sub

Michael

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: HowTo delete all lines ending in a certain string?

Joan Miquel Torres Rigo
In reply to this post by Christian Brabandt
2011/3/10 Christian Brabandt <[hidden email]>:

>
> :g/\.\.\?$/d

Technically this will also delete other file names if ends in a dot
(not a recommendable name, but possible at all).

This other one will avoid it:

:g/\(\s\.\|\/\.\)\.\?$/d


Regards.

--
Joan Miquel Torres__________________________________
Linux Registered User #164872
http://www.mallorcaweb.net/joanmiquel
BULMA: http://bulma.net http://breu.bulma.net/?l2301

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Loading...