0

I have file of 61 columns; I would like to calculate the standard deviation (SD) for each row with ignoring the 1st column and print the results against the 1st column, please note that the number of columns is not the same for each row and also some rows have only values for the first column which is not including in calculating the SD

input file
0.0  4  6  5  1  2  9  4  5  1  ..... 
0.5  3  1  
1.0  3  7  8  2  
1.5  3  3  3  4  6  4  5   
2.0  
2.5  6  7  6  9 
4
  • 1
    Off-topic, big time.
    – Cbhihe
    Jul 14, 2016 at 21:43
  • @Cbhihe Sounds like a homework question to me. Jul 14, 2016 at 21:47
  • @Cbhihe No, not really. It's a bit more involved than our average data processing question but not wildly off-topic. It may be a duplicate: Moshen, do check our existing questions. Jul 14, 2016 at 23:07
  • @Gilles: My interpretation (may be off) if that this has litterally nothing to do with *nix. Sure, it can be answered here, as it is... so perhaps in that sense is it not really off-topic. However it remains a sideline topic just holding by the one thread, we call ... awk. Maybe not fully "off-topic" but definitely on the wrong side of "borderline" (at best) ...
    – Cbhihe
    Jul 15, 2016 at 7:15

1 Answer 1

3

this is hardly a linux question

awk 'NF>1{ s=0;s2=0;c=NF-1 ;
           for (i=2; i<=NF;i++) { s+=$i ; s2+=$i*$i;}
           # compute sd from c,s and s2
           printf "%f\n",sqrt((s2/c)-(s/c)^2) ;}'
7
  • please check it again it gives syntax error Jul 14, 2016 at 20:05
  • 1
    @Cbhihe My edit corrected the syntax errors. Jul 14, 2016 at 21:54
  • 1
    @MohsenEl-Tahawy Are you trying to get us to do your homework for you? The answer is already 99% of what you asked for; surely you can go the final 1% on your own. Try reading the awk(1) man page as suggested, or perhaps read Apple’s tutorial. Jul 14, 2016 at 21:57
  • 1
    Hope you credit @Archemar when you submit your homework ;-)
    – steve
    Jul 14, 2016 at 22:24
  • 1
    @steve: Full credits to Archemar and Lawrence Velázquez...
    – Cbhihe
    Jul 15, 2016 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.