| |
| |
| |
|
Comments:
<0> hi all! If I've groupping in regular expressionin gawk, how could I acces that groups value later, for example in print command? <0> could anyone help me? <0> also {} statement afrer grouping doesn't work in regular expressions =( <0> for example /([[:digit:]]){5}/ doesn't matches 5 digits =( <1> redbaron: see --re-interval <1> about using the grouping matches, don't know (if it is possible, even)
<0> thx for re-interval advice <0> but access to grouping matches is a great feature of regexp, very usefull to parse text, tables, etc =( <1> redbaron: ah, see gensub for it <1> gensub() function <1> not sure if it is awk or Gawk-only <0> oh grat thx! <2> moo <3> foo <2> bar communication (tm xmb) <2> gensub is gawk only <4> trying to process a file with a format of " [0-9]+ [0-9]+ [a-z]+" e.g. " 22 10 somename" where the $3 has multiple entries, I am trying to sum up $1 and $2 per unique $3. <3> Ober: post an example line of text you want to use awk on <4> 1 22 proj.home <4> I have used prev before for single line add ups <4> just was not sure the proper way to sum by $3. if using an array would work for 2 values <3> post the output you want awk to create from the line: 1 22 proj.home <5> ober, awk '{ data[$3] += $1 + $2 } END { for (i in data) print i, data[i] }' <4> gnubien: 2 44 proj.home <4> sum($1) sum($2) $3 <4> having more than one value I was not sure how to do it with an ***ociative array <3> Ober: ($1*2) ($2*2) $3 <5> ober, awk '{ data[$3] = 1 ; d[$3, 1] += $1; d[$3, 2] = $2 } END { for (i in data) print i, d[i,1], d[i,2] }' <4> nice <5> always
<4> yeah need to up my awk foo <5> buh bye gnubien <4> this is quick, and I tire of "do it in perl" <4> thanks again, will take a while to grok this <5> np <5> its simple <5> the =1 is optional <4> yeah <4> I was accessing the elements wrong as well <5> gg <4> cat foo|awk '($3 == "test") { value = $2 } END{ print "value is:" value } <4> ok a line that has " 2007 22 test" <4> add a question to the end of that last statement <4> basically I ***umed that would work <6> Ober: Oh, it's working. <4> I guess it does work as a oneliner. <6> Ober: It'll work better if you don't omit the 'if' statement before the first test. <4> that's a consolidation from a script where \n is right before END <4> ok <4> oh well a oneliner works I guess <4> thanks <4> ($4 == "afs_cells") { afs_cells = $3;} <4> END{ print "afscells:" afs_cells ;} <4> ... found 54 'afs_cells' entries <4> first two lines from foo.awk last line is the input
Return to
#awk or Go to some related
logs:
#perl #perl what is dqs313_qmaster #math #bash etch xcompmgr gentoo grub append correct boot option #osdev xss accept-lang hdparm' failed in elive
|
|