LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   not parsing correctly (https://www.linuxquestions.org/questions/programming-9/not-parsing-correctly-661183/)

tostay2003 08-07-2008 10:42 AM

not parsing correctly
 
Hi All,

I have a file which contains the following data.
I basically want to extract first field if the second field is 'D'

[HTML]
Type &
Field......... Field. Field........ Conversion.. Column......... Output Depth &
Name.......... Number Definition... Code........ Heading........ Format Assoc..

@ID D 0 H_ID 10L S
CURRENT_DT D 0 CURRENT_DT 40L S
DAY_ID D 1 TIME_DAY_ID 40R S
@KEY PH CURRENT_DT

@ PH CURRENT_DT
DAY_ID
ID.SUP

5 records listed.
[/HTML]
For this I am using the followign code
Code:

awk -F' ' '{if ($2="D") print $1;}' filename
But I get the following result.

Quote:

Type
Field.........
Name..........

@ID
CURRENT_DT
DAY_ID
@KEY

@
DAY_ID
ID.SUP

5
where as this is what I am expecting.
Quote:

@ID
CURRENT_DT
DAY_ID
@KEY

ghostdog74 08-07-2008 11:10 AM

it should be "==" and not "=" in your if statement. Furthermore, there's no need for "if" either
Code:

awk '$2=="D"{print $1]' file


All times are GMT -5. The time now is 10:34 PM.