If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > awk and grep

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-29-10, 15:54
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
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
Reply With Quote
  #2 (permalink)  
Old 03-29-10, 16:00
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
grep -v REGION_2
eliminates REGION_2 rather than selecting.
Reply With Quote
  #3 (permalink)  
Old 03-29-10, 16:08
saccskiz saccskiz is offline
Registered User
 
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 )
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On