grep question - Aix

This is a discussion on grep question - Aix ; Hi, I'm preparing for an AIX test and one of the questions in the prep-exam is this: "Which command will display all lines in file1 that contain the string abc but NOT the string xyz?" The given correct answer is: ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: grep question

  1. grep question

    Hi,

    I'm preparing for an AIX test and one of the questions in the prep-exam
    is this:

    "Which command will display all lines in file1 that contain the string
    abc but NOT the string xyz?"

    The given correct answer is: grep -E "abc&!xyz] file1

    I doubt very much that this is a correct expression since actually
    testing it results in nothing. Am I correct?

    Thank you.

    Huub

  2. Re: grep question

    Huub wrote:
    > Hi,
    >
    > I'm preparing for an AIX test and one of the questions in the prep-exam
    > is this:
    >
    > "Which command will display all lines in file1 that contain the string
    > abc but NOT the string xyz?"
    >


    grep abc file1 | grep -v xyz

  3. Re: grep question

    On Jul 13, 9:53 am, Huub wrote:

    ....
    > "Which command will display all lines in file1 that contain the string
    > abc but NOT the string xyz?"
    >
    > The given correct answer is: grep -E "abc&!xyz] file1
    >
    > I doubt very much that this is a correct expression since actually
    > testing it results in nothing. Am I correct?


    The above command work not work at all - its looks like you made a cut
    and paste out of a PDF.

    The following command
    $ echo "abc\nabc xyz\n def xyz" | grep -E "abc|!xyz"
    gives:

    abc
    abc xyz

    so i would say the answer by the book is correct as may other ...
    And of cource its the AIX grep.

    hth
    Hajo


  4. Re: grep question

    > The above command work not work at all - its looks like you made a cut
    > and paste out of a PDF.
    >
    > The following command
    > $ echo "abc\nabc xyz\n def xyz" | grep -E "abc|!xyz"
    > gives:
    >
    > abc
    > abc xyz
    >
    > so i would say the answer by the book is correct as may other ...
    > And of cource its the AIX grep.
    >
    > hth
    > Hajo
    >


    It is from a pdf, but it didn't let me copy&paste so I had to type it
    over. The answer *does* have the &, not the |. So, considering your
    reply, I assume the & is wrong?
    Yes, I noticed that AIX versions of commands are (slightly) different
    from e.g. Linux versions.

  5. Re: grep question

    On Jul 13, 1:42 pm, Huub wrote:
    .....
    > It is from a pdf, but it didn't let me copy&paste so I had to
    > type it over. The answer *does* have the &, not the |. So,
    > considering your reply, I assume the & is wrong?


    yes it is since the & is not a valid operator afaik

    have a nice weekend
    Hajo



  6. Re: grep question

    Hajo Ehlers wrote:
    > On Jul 13, 1:42 pm, Huub wrote:
    > ....
    >> It is from a pdf, but it didn't let me copy&paste so I had to
    >> type it over. The answer *does* have the &, not the |. So,
    >> considering your reply, I assume the & is wrong?

    >
    > yes it is since the & is not a valid operator afaik
    >
    > have a nice weekend
    > Hajo
    >
    >


    Other point: in my o.p. the official correct answer was quoted "....]. I
    assume this is wrong as well and should be "...."?

  7. Re: grep question

    On Jul 13, 12:22 pm, Hajo Ehlers wrote:
    > On Jul 13, 9:53 am, Huub wrote:
    >
    > ...
    >
    > > "Which command will display all lines in file1 that contain the string
    > > abc but NOT the string xyz?"

    >
    > > The given correct answer is: grep -E "abc&!xyz] file1

    >
    > > I doubt very much that this is a correct expression since actually
    > > testing it results in nothing. Am I correct?

    >
    > The above command work not work at all - its looks like you made a cut
    > and paste out of a PDF.
    >
    > The following command
    > $ echo "abc\nabc xyz\n def xyz" | grep -E "abc|!xyz"
    > gives:
    >
    > abc
    > abc xyz
    >
    > so i would say the answer by the book is correct as may other ...
    > And of cource its the AIX grep.
    >
    > hth
    > Hajo


    Is that right? The orginal question was

    "Which command will display all lines in file1 that contain the
    string
    abc but NOT the string xyz?"


    But the regexp above is definitley displaying a line containing string
    xyz..

    if file1 is
    abc
    abc def
    xyz abc

    I would expect the correct regexp to display

    abc
    abd def

    I could do it in python with negative look-ahead and look behind
    assertions (match this regexp if it isnt followed by this other
    regexp) but not sure how to achieve it in unix grep.


  8. Re: grep question

    On Jul 13, 12:22 pm, Hajo Ehlers wrote:
    > On Jul 13, 9:53 am, Huub wrote:
    >
    > ...
    >
    > > "Which command will display all lines in file1 that contain the string
    > > abc but NOT the string xyz?"

    >
    > > The given correct answer is: grep -E "abc&!xyz] file1

    >
    > > I doubt very much that this is a correct expression since actually
    > > testing it results in nothing. Am I correct?

    >
    > The above command work not work at all - its looks like you made a cut
    > and paste out of a PDF.
    >
    > The following command
    > $ echo "abc\nabc xyz\n def xyz" | grep -E "abc|!xyz"
    > gives:
    >
    > abc
    > abc xyz
    >
    > so i would say the answer by the book is correct as may other ...
    > And of cource its the AIX grep.
    >
    > hth
    > Hajo


    The original question was;

    "Which command will display all lines in file1 that contain the
    string
    abc but NOT the string xyz?"

    The regex you listed above definitley is showing the line
    abc xyz

    given a file1 of
    abc
    abc def
    xyz abc
    abc xyz
    def abc

    I would expect the correct regexp to display
    abc
    abc def
    def abc

    I could do it in python with negative look behind and negative look
    ahead assertions, but I'm not sure how to do it in regular grep
    without using multiple grep's with a pipe.



  9. Re: grep question

    apologies for double post. Thought google had lost the other one


+ Reply to Thread