Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a long text file listing dups-23Mar16.listing I want to delete lines beginning, for example, with .local. Here are some lines in this file:

Desktop/Reisen/Italien/VillaLaBandita/images-hpz-urlaub/cimg0429.jpg
Desktop/Tiere/Italien/VillaLaBandita/images-hpz-urlaub/cimg0429.jpg
.local/share/files/eksteuer/ekst.odt

From outside of this file I can do this with the command

sed  -e '/^\.[a-z]/d' dups-23Mar16.listing

and in a vi buffer by

:%!sed  -e '/^\.[a-z]/d'

If I want to remove the lines beginning with Desktop as well I succeed with

:%!sed  -e '/^Desktop/d'

How can I combine both commands into one? I tried

:%!(sed  -e '/^\.[a-z]/d';sed -e '/^Desktop/d')

but this does not work. What is the solution?

share|improve this question

If you really want that, you can simply give multiple -e parameters to sed like this:

:%!sed -e '/^\.[a-z]/d' -e '/^Desktop/d'

I just don't know if you want this just for some experience in sed or you are not aware that inside vim, there is ed that knows everything sed does and more... and without starting an unnecessary process:

g/^\(\.[a-z]\|Desktop\)/d
share|improve this answer
    
I simply did'nt know better. Helpful for both: experience in sed and the learning power of ed. Each version does what I want. Thank you! – Lermontov Mar 24 at 20:18

If you want to do this at the vi buffer command line, this should work--without sed:

:exe 'g/^Desktop/d'|g/^\.[a-z]/d

The vertical bar separates multiple commands on a vi command line. The g works to process the entire buffer, as the Regular expressions should qualify the delete commands to work with every line that matches. The exe and quotes are needed to prevent a global recursion error.

share|improve this answer
1  
You wrote "The g works to process the entire buffer", but there is no g in your command, where do I have to place it. As it stands the command did not properly. I would be grateful seeing a corrected version. – Lermontov Mar 24 at 20:07
    
My bad. I made a couple of edits and managed to drop that correction on the floor. Fixed now. Hope this helps! – Greg Tarsa Mar 25 at 17:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.