Script for counting some columns in file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anisha
    New Member
    • Feb 2014
    • 1

    Script for counting some columns in file

    Hello!!
    I have a query to count the last column of the file and print it as shown in the below format!!
    I tried using ths but dint work

    cut fileWithLotsOfC olumns.txt -d" " -f 1,2,3,4 >fileWithOnlyFi rst4Cols.txt

    plz help me

    output should be something like this!!!






    AF1 AF2 AM1 AM2 EF1 EF2 EM1 EM2
    FBgn0033056 119 301 205 141 317 153 506 319
    FBgn0037888 20 41 41 22 30 17 57 34
    FBgn0034742 3193 3642 2558 2005 1687 1746 3039 3610
    FBgn0032640 1243 2804 1969 2130 1777 1536 3143 3259
    FBgn0259204 469 1566 971 962 1214 783 1872 1602
    FBgn0039821 56 58 36 34 35 46 49 87
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    But how does your input look like?

    If you have i.e. this:
    Code:
    a 1 2
    b 3 4
    than you can add a column with this:
    Code:
    awk '{ sum=sum+$3 }END{ print sum }
    which should output '6'

    Comment

    Working...