The AWK script below will do this. Save it into a file called "addnums", make it executable with chmod +x, and run it with:
 
addnums datafn
 
where datafn in the name of the file with the data in it.
 
 
#!/bin/awk -f
 
NR == 3 {
  num1 = $2;
}
 
NR == 6 {
  print $2 + num1;
  exit;
}
 
   Regards,

      Craig Southeren

 -------------------------------------------
 Equivalence - Home of FireDoor, MibMaster & PhonePatch
 For Open Source H.323 - see http://www.openh323.org

 Email: [EMAIL PROTECTED]
 Web:   http://www.equival.com.au
 Fax:   +61 2 4368 1395        Voice: +61 2 4368 2118
-----------------------------------------------------
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Shrestha
Sent: Friday, 7 January 2000 15:07
To: [EMAIL PROTECTED]
Subject: [SLUG] addition using script file

Suppose there is a file, which contains:
 
a 12
b 14
g 9
p 58
d 25
t 18
w 32
 
 
The two fields are seperated by space.
If we have to add all the numbers of second field using script file, it can be done using cut -d" " -f2 /file
 
Can any one help to write a script file which adds the number from third line to sixth line only.
 
Any help will be highly appreciated!!
 
Shre
 

Reply via email to