awk output not what was expected

Good Moring,
I am currently reading about awk in a manual and following the examples using the oratab file.
My system is SOLARIS 10
I think I am getting strange behavior judging by what the book says to do and what I am getting with my little program.
Here is my program:

grep -v  [#]  oratab | /usr/xpg4/bin/awk    'BEGIN  { RS = ":" } ;   /Y/   { print   $1,   $3 }'

sample from oratab: Before parsing.

#dlspfx:/oracle/product/10.2.0/db05_2:Y
#dlpayx:/oracle/product/10.2.0/db05_2:Y
dlqdbx:/oracle/product/10.2.0/db05_2:N
tundtimx:/oracle/product/11.2.0/dbhome_4:Y

EXPECTED OUTPUT:

dlspfx          Y
dlpayx         Y
tundtimx      Y

But my actual is:

ACTUAL OUTPUT:

Y
Y
Y

It appears that something has shifted and I can�t figure out what is wrong with my syntax in the original statement.

grep -v  [#]  oratab | /usr/xpg4/bin/awk    'BEGIN  { RS = ":" } ;   /Y/   { print   $1,   $3 }'

I did the following print and the output is below it.

FIELD $0: suppose to return the entire string ex. tsaimx:/oracle/product/11.2.0/dbhome_3:Y but doesn�t. It returns the correct information but in reverse order: field $3 then $1. It should be the other way around.

grep -v  [#]  oratab | /usr/xpg4/bin/awk 'BEGIN { RS = ":" } ;  /Y/ { print   $0 }'
Y
as10gr2
Y
cmf1
Y
cmf2

This should have printed out all 3 fields but doesn�t. Only field 1 and 3 are printed and they are also printed in reverse order.

grep -v  [#]  oratab | /usr/xpg4/bin/awk 'BEGIN { RS = ":" } ;  /Y/ { print $1, $2, $3 }'
Y      as10gr2 
Y      cmf1 
Y      cmf2 
Y      cmf9

This command prints the field that is NOT LISTED in the print command !!! It prints field number 1.

grep -v  [#]  oratab | /usr/xpg4/bin/awk  'BEGIN { RS = ":" } ;   /Y/  { print    $2, $3 }'

record: tsaimx:/oracle/product/11.2.0/dbhome_3:Y

cmf2 
cmf9 
dev101 
tundaimx 
tundatmx 
tundcllx

Why isn�t my program working as expected?

Any help on this matter would be appreciated.

thanks in advance

Hi,
RS is record separator
FS is field separator
So, replace in your code, RS by FS.

Regards.

1 Like

You want to set the field separator FS, not the record separator RS, which controls what is viewed as delimiting lines.

You want to separate fields on ":" not records...

grep -v [#] ~/tmp/tmp.dat  | awk -F\: '/Y/ { print $1, $3 }'
tundtimx Y

Also you deliberately remove anything with a hash "#" in it prior o feeding awk.

I found the problem:

grep -v  [#]  oratab | /usr/xpg4/bin/awk 'BEGIN { RS = ":" } ;  /Y/ { print $1, $3 }'

The RS in the begin statement should have read FS.

this thread can be closed.

thanks

grep -v  [#]  oratab | /usr/xpg4/bin/awk 'BEGIN { FS = ":" } ;  /Y/ { print $1, $3 }'

---------- Post updated at 11:10 AM ---------- Previous update was at 11:09 AM ----------

Yes you are right. I just found that out.

thanks for getting back too me.

---------- Post updated at 11:12 AM ---------- Previous update was at 11:10 AM ----------

Yes you are right. I reviewed my notes and that is what it said in the book.

chalk it up to a lack of experience.

Regards