Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

field question
I have input with 7 fields.  If field 6 equals X print field 2.  X is
numerical in this case but could be text.

What's the awk syntax for this?

Thanks.

~F

Report this thread to moderator Post Follow-up to this message
Old Post
Faeandar
12-02-04 08:55 AM


Re: field question
On 2004-12-02, Faeandar wrote:
> I have input with 7 fields.  If field 6 equals X print field 2.  X is
> numerical in this case but could be text.
>
> What's the awk syntax for this?

awk '$6 == X {print $2}' X=search_string

--
Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
 ========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License

Report this thread to moderator Post Follow-up to this message
Old Post
Chris F.A. Johnson
12-02-04 08:55 AM


Re: field question
On 2 Dec 2004 03:14:41 GMT, "Chris F.A. Johnson"
<cfajohnson@gmail.com> wrote:

>On 2004-12-02, Faeandar wrote: 
>
>awk '$6 == X {print $2}' X=search_string

That's it?!  Sheesh, why does the book not address that anywhere?
Thought it was a little more exotic for some reason.

If X is test does it need to be quoted?

Thanks.

~F

Report this thread to moderator Post Follow-up to this message
Old Post
Faeandar
12-02-04 08:55 AM


Re: field question
In article <059tq0p5ha619t1kq8dseh5iia0m2guu5v@4ax.com>,
Faeandar <mr_castalot@yahoo.com> wrote:

> On 2 Dec 2004 03:14:41 GMT, "Chris F.A. Johnson"
> <cfajohnson@gmail.com> wrote:
> 
>
> That's it?!  Sheesh, why does the book not address that anywhere?
> Thought it was a little more exotic for some reason.
>
> If X is test does it need to be quoted?

only if there are spaces

awk '$0 ~ X {print $2}' X='search string with spaces'

But note, I changed the test since awk parses fields by spaces.

The variable assignment should work for any awk, but most awks also allow

awk -v X='search string with spaces' '$6 == X {print $2}'

syntax, where you can have as many -v options as you like, and the
advantage here is that -v specified variables are available during the
BEGIN {...} Pattern{action} pair

Bob Harris

> Thanks.
>
> ~F

Report this thread to moderator Post Follow-up to this message
Old Post
Bob Harris
12-02-04 08:56 PM


Re: field question
On 2 Dec 2004 03:14:41 GMT, "Chris F.A. Johnson"
<cfajohnson@gmail.com> wrote:

>On 2004-12-02, Faeandar wrote: 
>
>awk '$6 == X {print $2}' X=search_string

That's it?!  Sheesh, why does the book not address that anywhere?
Thought it was a little more exotic for some reason.

If X is test does it need to be quoted?

Thanks.

~F

Report this thread to moderator Post Follow-up to this message
Old Post
Faeandar
12-07-04 08:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:06 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.