If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Shell scripts req'd...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-22-04, 22:43
malinut89 malinut89 is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
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
File Type: txt levels1.txt (7.2 KB, 42 views)
Reply With Quote
  #2 (permalink)  
Old 02-23-04, 02:35
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
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) :
Quote:
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On