Results 1 to 3 of 3

Thread: awk and grep

  1. #1
    Join Date
    Feb 2004
    Posts
    143

    Unanswered: awk and grep

    Am on sun solaris 5.10. I have a file called listings for which the contents look like this :

    #Db Region Welcome
    db1 REGION hello
    db1 DISTRICT hello
    db1 REGION_1 hello
    db1 DISTRICT_1 hello
    db1 REGION_2 sql
    db1 DISTRICT_2 sql
    db1 REGION_5 hello
    db1 DISTRICT_5 hello
    db1 REGION_3 hello
    db1 DISTRICT_3 hello
    db1 REGION_4 hello
    db1 DISTRICT_4 hello
    db2 REGION hello
    db2 DISTRICT hello
    db2 REGION_1 hello
    db2 DISTRICT_1 hello
    db2 REGION_2 hello
    db2 DISTRICT_2 hello
    db2 REGION_5 hello
    db2 DISTRICT_5 hello
    db2 REGION_3 hello
    db2 DISTRICT_3 hello

    I am trying to write a shell command that can retrieve me the 3rd parameter to the rightmost side.
    For example, if I say db1 and REGION_2, I need to see the result as :

    sql

    I tried this using the following:

    echo Sac=`awk '/^[^#]/' ${BASEDIR}/listings | grep -i db1 | grep -v -i REGION_2 | awk '{print $3}'`

    Unfortunately, I am getting the results as :

    Sac=hello hello hello hello sql hello hello hello hello hello hello

    What in the world am I doing wrong ? Any suggestions would be helpful. Thanks

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    grep -v REGION_2
    eliminates REGION_2 rather than selecting.

  3. #3
    Join Date
    Feb 2004
    Posts
    143
    Thanks a lot kitaman for your very quick response... I now have what I needed...
    (that was silly of me to have overlooked the -v )

Posting Permissions

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