It is currently Tue, 07 Dec 2021 02:31:02 GMT



 
Author Message
 How to grab a token from a line in file then compute all of these tokens
I'm goint to write a Bourne Shell script but have a problem,say

if the input file as:
IBM AAA 200 50.12
AT&T AAA 1212 320.2
SUN BBB 123 121.00
CICSO AAA 134 54.12
..

and I have to grab all the matched tokens (like AAA) which are in a
certain field, like in the last field then make some computing.

I know the command grep is for displaying all lines that contain a
certain token, and cut is for grab tokens vertically from a file, but
I have no idea how to apply grep and cut together and cast the token
to a numeric.

Does any one have idea ?

Thanks lots

John



 Mon, 18 Apr 2005 12:16:07 GMT   
 How to grab a token from a line in file then compute all of these tokens

   As I pointed out in response to your previous post, this would be
   better in comp.unix.shell.

          awk '$2 == "AAA" {
                        print "Field 2 is " $2
                        print "Field 3 is " $3
                        print "Field 4 is " $4
                        printf "The sum of fields 3 and 4 is %d\n\n", $3 + $4
                      }' FILENAME

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2002, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License



 Mon, 18 Apr 2005 16:55:25 GMT   
 
   [ 2 post ] 

Similar Threads

1. token ring token ring token ring

2. question on shell script for grabbing a token from a string

3. question on shell script for grabbing a token from a string

4. Cluster Computing -Token Ring vs. Ethernet-

5. token token

6. TOKEN RING? (unfortunately *IBM* Token Ring)

7. use sed to split tokens into lines

8. Grab line with spaces in a file

9. how to grab a line # from file (awk)

10. Token Ring Breaks my file system


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software