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