Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #1477
| From | Bill Marcum <bill@lat.localnet> |
|---|---|
| Newsgroups | comp.lang.awk, comp.os.linux.misc |
| Subject | Re: Re (2): Can awk use `grep`? |
| Date | 2011-06-27 01:55 -0400 |
| Organization | PWN - Penguins With Nukes |
| Message-ID | <slrnj0g6qm.3ft.bill@lat.localnet> (permalink) |
| References | <iu7414$bnp$1@speranza.aioe.org> <iu7sa1$3un$1@dont-email.me> |
Cross-posted to 2 groups.
On 2011-06-26, no.top.post@gmail.com <no.top.post@gmail.com> wrote:
> In article <iu7414$bnp$1@speranza.aioe.org>, pk <pk@pk.invalid> wrote:
>
>> With awk, the usual way to do that is:
>>
>> awk 'NR==FNR{a[$1]=$2;next}{print $0, a[$0]}' Input2 Input1
>>
> Thanks, a superficial test looks ok.
> My real problem is more complex than I described,
> and I'd like Input2 Input1 to be 2 functions: PT DV.
> So I'm guessing that I'd just use:
> `PT' `DV`
>
> I too used to be guilty of one-lineism when younger.
> Too bad for other maintainers - I'm not paid to be a tutor.
> { // the matching conditions are
> a[$1] // the 1st field of an entity bound to 'a'
> =$2 // equals the 2nd fiel of the input line
> ; // and also ??
> } // end of matching conditions
No, conditions are outside of braces. The expression above is the
action for the condition NR==FNR. You left out "next", which means to
ignore any following actions and start processing the next record.
The following action is always executed unless it's skipped by "next".
By the way, NR==FNR is true while reading the first file in a list.
FNR counts the records in the current file, and NR counts all records.
> { // start action for matching condition/s
> print $0 // print 1st field of the input line
> , // and
> print 1st field <related to> the 'a' entity
> }' // end of <awk> except for input args
> Input2 Input1 // input 2 files in unknown sequence.
>
> `awk` is a DEVIL !!
>
>
--
Inside every older person is a younger person wondering what the hell
happened.
Back to comp.os.linux.misc | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re (2): Can awk use `grep`? no.top.post@gmail.com - 2011-06-26 18:03 +0000
Re: Re (2): Can awk use `grep`? Bill Marcum <bill@lat.localnet> - 2011-06-27 01:55 -0400
Re: Re (2): Can awk use `grep`? Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2011-06-27 12:51 +0100
Re: Re (2): Can awk use `grep`? gazelle@shell.xmission.com (Kenny McCormack) - 2011-06-27 12:18 +0000
Re: Re (2): Can awk use `grep`? Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2011-06-28 13:30 +0100
Re (3): Can awk use `grep`? no.top.post@gmail.com - 2011-06-28 03:24 +0000
Re: Re (2): Can awk use `grep`? Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-06-27 07:18 +0000
Re: Re (2): Can awk use `grep`? Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-06-27 22:02 +0200
Re (3): Can awk use `grep`? no.top.post@gmail.com - 2011-07-05 17:34 +0000
csiph-web