Professional Web Applications Themes

problem with grep - Sun Solaris

I am trying to get a list of only certain files in a directory. In this directory there are some files named inc_base.d amongst others. I want to select only the ones not named inc_base. I tried this "ls | grep '^[^inc_base]' ". And this works for not giving me the inc_base files, but it does not give me all of the other files. All of the files sorted before inc_base, with the exception of the one file sorted just before the inc_base files, do not show up. All the files sorted after inc_base do appear though. So i would ...

  1. #1

    Default problem with grep

    I am trying to get a list of only certain files in a directory.
    In this directory there are some files named inc_base.d amongst
    others. I want to select only the ones not named inc_base.
    I tried this "ls | grep '^[^inc_base]' ". And this works for not
    giving me the inc_base files, but it does not give me all of the other
    files. All of the files sorted before inc_base, with the exception of
    the one file sorted just before the inc_base files, do not show up.
    All the files sorted after inc_base do appear though. So i would like
    to know why only the files sorted after inc_base are listed with the
    above command ? What am i doing incorrectly ? Thanks.
    joao Guest

  2. #2

    Default Re: problem with grep

    "joao coelho" <pt> wrote in message
    news:google.com... 

    ^[^inc_base] means everything that does not begin with the character 'i' 'n'
    'c' 'b' 'a' 's' and 'e'.


    Crusher Guest

  3. #3

    Default Re: problem with grep

    "joao coelho" <pt> wrote in message
    news:google.com... 

    ^[^inc_base] means everything that does not begin with the character 'i' 'n'
    'c' '_' 'b' 'a' 's' and 'e'.


    Crusher Guest

  4. #4

    Default Re: problem with grep

    joao coelho wrote:
     

    You are close, but you have negated a class of characters instead
    of a whole string.

    grep's regular expressions don't let you do what you want, so you
    have to use a command-line argument to grep in addition to a regular
    expression:

    ls | grep -v inc_base

    Or if they all begin with "inc_base" (rather than just containing it),
    you should be more specific:

    ls | grep -v '^inc_base'

    Hope that helps.

    - Logan

    Logan Guest

  5. #5

    Default Re: problem with grep

    joao coelho wrote: 

    Let's say I want all files in the current directory that
    don't contain the words "hello" or "fred".

    $ ls | egrep -v '(hello|fred)'

    egrep makes it easy to do multiple patters like this.

    Chris Guest

Similar Threads

  1. grep in php
    By Papa in forum PHP Development
    Replies: 2
    Last Post: March 31st, 12:46 PM
  2. using grep in perl
    By Andrew Gaffney in forum PERL Beginners
    Replies: 3
    Last Post: February 3rd, 05:03 PM
  3. grep with ftp
    By Shaunn Johnson in forum PERL Beginners
    Replies: 9
    Last Post: September 12th, 06:51 AM
  4. Help with grep
    By Kevin in forum Sun Solaris
    Replies: 3
    Last Post: September 4th, 07:11 AM
  5. grep
    By Anders Bystrup in forum PERL Miscellaneous
    Replies: 3
    Last Post: August 7th, 09:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139