Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    4

    Unanswered: Shell scripts req'd...

    I need two shell scripts to modify the attached file. One needs to display only lines 10 thru 20 (exclude all others). The other script would make a new file that consists of two columns: the year, and the average value for the first six months of the year (columns 2-7).

    Thank you in advance for your help!
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Hi,

    To display lines 10 to 20 do :

    Code:
    sed -n '10,20p' levels1.txt
    To create the second file :

    Code:
    awk ' 
    NR==1 { 
       print "YEAR AVERAGE"; 
       next;
    }
    NF>= 7 {
       sum = 0;
       for (field=2; field<=7; field++)
           sum += $field;
       print $1,sum/6;
    }
    ' levels1.txt  > levels1_average.txt
    The result (partial) :
    YEAR AVERAGE
    1900 17392,7
    1901 17370
    1902 17372,2
    1903 17403,3
    1904 17404
    1905 17386,8
    1906 17398
    1907 17415
    1908 17422,2
    1909 17396,3
    1910 17388,3
    1911 17375,2
    1912 17388,2
    1913 17425
    1914 17399
    1915 17375,3
    1916 17400,5
    1917 17394,5
    1918 17395,8
    1919 17418,5
    1920 17378,3
    Jean-Pierre.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •