LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   FS=? in gawk (http://www.linuxquestions.org/questions/programming-9/fs%3D-in-gawk-62281/)

realos 05-28-2003 09:55 AM

FS=? in gawk
 
hi,
I am having some stupid problem with regular expressions in gawk.

me@pc> gawk -f test.awk test.log
does not find print anything on stdout.


..............test.awk .................
/^DESCRIPTION$/ {print "test passed!"}


.................EOF ............................
.................test.log....................
DESCRIPTION 123


................EOF.....................

Can any one help? Since FS seperates fieds after a blank space there should not be any need of resetting it.


man page revels following:

^ ......matches the beginning of a sting
$ ......matches the end of a string
FS ......the input field seperator, a space by default,


thanks for any idea,

vladkrack 05-28-2003 03:46 PM

The problem is that in you are testing if the string has only the word "DESCRIPTION" in the line (start the line, has the word, finish the line). You can test the test.awk without the $ (end of the line), and then the test will pass...

realos 05-28-2003 07:30 PM

vladkrack,

Okay, I got it. Strings are equal to records (=lines) and not fields (words). That is why i tried to use /^DESCRIPTION$/.

I have a logfile like here:
---------------------------test.log-----------------
{white_space_not_visible_here} DESCRIPTION
{white_space}xx
{white_pace}SOME_DESCRIPTION_X
-------------------------------------------------------

Only the first DESCRIPTION should cause an action to take place. Well, with /^[ \t]*DESCRIPTION$/ it is working fine.

thanks,


All times are GMT -5. The time now is 07:23 PM.