@# Quotes DB     useful, funny, interesting





Google
 
Web www.quotesdb.info
Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Dalnet  |  Ircnet  |  Galaxynet


Comments:

<0> my awk is hanging: http://rafb.net/paste/results/r6LR7a66.html
<0> how do i properly print "sum" out of BEGIN{}, because i need to use it outside of the begin function
<1> END {print sum;}
<1> Possibly.
<0> still hangs
<0> i can properly print it in the BEGIN{} function
<0> but hangs everywhere else
<1> ok
<1> hedpe: awk -v file="$1"
<1> you can set variables like that



<1> what's in $1 ?
<0> its just a filename you p*** to the script
<1> Indeed.
<1> What's in the file?
<0> lines which consist of 3 numbers seperated by white space
<1> and what do you want to achieve?
<0> i need to get the standard deviation of the all of the numbers... so in BEGIN{} i was going to get the sum, average, and compute standard deviation... then in the main body i want to check which numbers are greater than 3x the standard deviation, print $1 for those that are
<0> i just don't understand why it hangs trying to print a variable in the main body
<2> hedpe: What you're doing in BEGIN should probably be your input.
<1> it doesn't read the file until after BEGIN
<2> hedpe: And your { print sum } should probably be: END { print sum; }
<0> pr3d4t0r: what do you mean it should be my input
<0> goldfish: but i can reconstruct and print each line in BEGIN
<2> hedpe: How about this:
<2> hedpe: awk '{ if ($3 != 0) { nSum += $3; nCount++; } } END { print nSum; }' < $1
<0> pr3d4t0r: if i have to make two p***es through the data, if its very small in size... as in 280 lines at a time, should i just read it into memory while i do the sum stuff, then read from the memory to test the standard deviations?
<2> hedpe: Did you try that yet?
<0> sorry, i sent you a question after you quit
<0> yes that does work
<0> pr3d4t0r: if i have to make two p***es through the data, if its very small in size... as in 280 lines at a time, should i just read it into memory while i do the sum stuff, then read from the memory to test the standard deviations?
<2> hedpe: Sure.
<2> hedpe: I read much more than 280 lines at one time, no sweat.
<2> hedpe: Also, look at functions. You can define functions and you can define ***ociative arrays and all kinds of stuff.
<2> hedpe: Now... why do you need to p***es?
<2> hedpe: *Maybe* all you need is two function calls ON THE SAME DATA as it's read in the main input body.
<0> pr3d4t0r: the first p*** is used to compute the standard deviation... the second p*** is to test all the values against the standard deviation
<0> but how could i know the standard deviation without parsing through all the data first?
<2> hedpe: Heh. I knew you were going to say that. I wrote a similar script a couple of nights ago :)
<2> hedpe: No, you're right.
<2> hedpe: So.
<0> hehe
<2> hedpe: Build the data and calculate the stddev from the main loop and in the first clauses of END.
<2> hedpe: Then do the rest of your processing in a function that you call from END.
<0> got ya, i think i can handle this now :)
<0> thanks for the help!
<2> hedpe: Here: awk '{ dSum += $3; dData[nCount++] = $3; } END { /* use dData array here */ }' < "$1"
<2> hedpe: You're welcome. Have fun.
<2> hedpe: And go look at functions.
<2> hedpe: http://eugeneciurana.com/pastebin/pastebin.php?show=10258
<3> hi everyone
<4> lnxnt: hi
<3> is this correct to check if the first field does not contain a blank? $1 !~ /^ /



<3> :)
<4> lnxnt: awk will skip over the blank space before the first word in a line so its not necessary imho
<4> awk sees "no space" the same as " no space"
<3> hm
<3> saving the first word of each line in a variable. I want to skip blank lines (or lines beginning with blanks)
<3> I mean
<3> v = $1; print v
<3> if v is empty then skip
<4> lnxnt: echo " no space" |awk '{if ($0 !~ /^ /) print}'
<4> lnxnt: then try this: echo "no space" |awk '{if ($0 !~ /^ /) print}'
<3> gnubien: possibly, blanks in files cause problems?
<3> gnubien: lines (in vim) that are created with o without inserting anything
<3> gnubien: where is the output if I get "warning, output is not on terminal"? :)
<3> gnubien: how do I escape from that
<3> ctrl Z
<4> vim error?
<3> oh, right
<4> lnxnt: ask in #bash i dont use vim
<2> lnxnt: You have a different problem.
<2> lnxnt: Blank lines in vim are fne.
<2> Er, fine.
<3> pr3d4t0r: I used regex ^$ to identify them
<3> Is it possible to read the next line in one skript
<3> ?
<3> for example to compare first and second line of a file
<2> lnxnt: In awk it's better to read your scripts one line at a time unless you can logically separate groups of lines.
<2> lnxnt: So yes, you can do that but you need to figure out what the logical groupings are.
<2> What the ****?
<3> pr3d4t0r: logical groupings? :)
<3> sorry, i wanted to meditate about "logical groupings" and fall asleep
<3> is it possible to read every line again, a second time?
<5> how can i truncate a decimal from a variable, so its only an "int" ?
<2> hedpe: man awk
<2> hedpe: The section on built-in commands.
<5> do you know of a better way to do this? http://rafb.net/paste/results/3Upmzz58.html
<5> i am trying to correctly output an integer as 2 numbers
<5> like 0, i need 00, 5 i need 05
<5> so i'm testing if its less than 10 and appending a 0 in the printf
<2> hedpe_: man printf
<2> hedpe_: nX = 42; printf("%03d\n", nX);
<2> hedpe_: Try this: awk 'BEGIN { printf("%03d\n", 42);} '
<2> hedpe_: Tell me later what you see. I'm going to my office now.
<5> pr3d4t0r: great, thank you
<6> guys... I'm trying to read some dude's code, and it's completely insane. However, I am not very good with awk and I was wondering if someone could take the time to translate this line for me "printf(" Intervju denne uke :%2d.0%1d %4d(%4d) ",(umtidcom/umantcom)/60,rumm,umantcom,uantcom)". What, exactly, does this thing do? Most importantly, how is it using the rumm, umantcom and uantcom variables? Please, I need to figure this out.
<2> scoobie2: man printf
<2> scoobie2: He's formatting the output as "two digits plus one decimal", then "4 digits", then "(four digits)".
<2> scoobie2: Oh, and only one digit for %1d; I missed that.
<2> scoobie2: He's doing that so that the printf() output is nicely set in columns.
<6> ah
<6> thanks


Name:

Comments:

Please enter the result of the sum 63 + 46 (to avoid spam):






Return to #awk
or
Go to some related logs:

#gentoo
could not find working GL library ubuntu
etch wpa_supplicant setup
#perl
xorg protocol imp ps/2
#python
#php
Access denied for user 'root'@'localhost' +mysql +ubuntu
#css
#ubuntu



Home  |  disclaimer  |  contact  |  submit quotes