LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-07-2008, 10:42 AM   #1
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Rep: Reputation: 15
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

Last edited by tostay2003; 08-07-2008 at 10:44 AM.
 
Old 08-07-2008, 11:10 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
it should be "==" and not "=" in your if statement. Furthermore, there's no need for "if" either
Code:
awk '$2=="D"{print $1]' file
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing using awk tungaw2001 Programming 2 03-27-2007 05:45 AM
XML parsing in C irfanhab Programming 3 05-06-2006 12:47 AM
Apache-ssl not correctly parsing php files jme Linux - Software 2 05-03-2005 12:04 PM
Parsing with Vim mijohnst Linux - General 2 06-18-2004 09:38 AM
Parsing. liguorir Programming 2 09-04-2003 04:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration