Regular expression with Grep command - Aix

This is a discussion on Regular expression with Grep command - Aix ; I have a file whose each line looks like: Description: SNL,CENT,8.0,ALP,UPSL,IE,38043759 2CPUS Description: ABC,nmji,6.0,gtP,buyL,MAC,38049 2CPUS ........ ........ Using the grep command, how will I find all those lines in my file that DO NOT begin with "Description: SNL". What regular ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Regular expression with Grep command

  1. Regular expression with Grep command



    I have a file whose each line looks like:

    Description: SNL,CENT,8.0,ALP,UPSL,IE,38043759 2CPUS
    Description: ABC,nmji,6.0,gtP,buyL,MAC,38049 2CPUS
    ........
    ........

    Using the grep command, how will I find all those lines in my file
    that DO NOT begin with "Description: SNL". What regular expression
    would I use for this?

    Thanks,

    Tushar Chandra

  2. Re: Regular expression with Grep command

    On 09/16/2008 01:10 AM, Tushar wrote:
    >
    > I have a file whose each line looks like:
    >
    > Description: SNL,CENT,8.0,ALP,UPSL,IE,38043759 2CPUS
    > Description: ABC,nmji,6.0,gtP,buyL,MAC,38049 2CPUS
    > .......
    > .......
    > Using the grep command, how will I find all those lines in my file
    > that DO NOT begin with "Description: SNL". What regular expression
    > would I use for this?


    grep -ve "^Description: SNL" FILE

    Regards,
    Niel

  3. Re: Regular expression with Grep command


    Thanks for your response. Your suggested command did exactly what I
    wanted for the scenario I described. But, what if my file is like:

    SN1
    Description:SNL,CENT,8.0,ALP,UPSL,IE,38043759 2CPUS
    Credit: This is a credit.


    SN2
    Description: ABC,nmji,6.0,gtP,buyL,MAC,38049 2CPUS
    Credit: This is a negative credit.


    .........
    .........


    Here's what I want to do. For every line that matches "Description:
    SNL", I want to get rid of 1 line before and after that line. So in
    this example, I would only want the following in my output :

    SN2
    Description: ABC,nmji,6.0,gtP,buyL,MAC,38049 2CPUS
    Credit: This is a negative credit.

    ........
    ........

    I ve been trying to use grep -A 1 -B 1 but am not able to use them
    with -v in grep. please help.


  4. Re: Regular expression with Grep command

    Since this is an AIX forum, I will give you an AIX suggestion.

    Look at the grep command option "-p"
    (-p doesn't exist in my flavor of linux, and I don't know that it is
    part of any other os)

    Hope this helps.

    --Casey

+ Reply to Thread