LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can it serve the purpose with 'awk' program? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-it-serve-the-purpose-with-awk-program-751246/)

Rode 08-30-2009 08:28 AM

How can it serve the purpose with 'awk' program?
 
Hello, guys

I met the troubles in calculating the sum of the products referring to the input file as follow,

0.900
0.100
0.900
0.100
0.800
0.200
1.000
10.238558
6.967603
10.238558
6.967603
7.860238
10.098804
12.669123

from which the products are calculated by multiplying the number in row 1 with that in row 8, row 2 with that in row 9, others done by analog.

thanks.

colucix 08-30-2009 08:45 AM

Welcome to LinuxQuestions! :)

What is the purpose of this script? Homework? How many lines it contains? If it is a very large file (I mean yours posted above is just an example) I'd start by splitting the file using split, so that it is far more easy to manage couples of values.

pixellany 08-30-2009 08:59 AM

Give us an example of what you have tried---and: Why you want to use Awk?

Since BASH does not support non-integer math, you will need a utility like "bc"---or maybe just use Python.

colucix 08-30-2009 09:02 AM

Quote:

Originally Posted by pixellany (Post 3662812)
Since BASH does not support non-integer math, you will need a utility like "bc"---or maybe just use Python.

AWK will serve this purpose as well! :)

pixellany 08-30-2009 09:07 AM

Quote:

Originally Posted by colucix (Post 3662816)
AWK will serve this purpose as well! :)

I guess I knew that.......not being an "Awker", I just guessed that it might not be the #1 choice here-----unless of course the instructor specified it..;)

colucix 08-30-2009 09:09 AM

Quote:

Originally Posted by pixellany (Post 3662822)
unless of course the instructor specified it..;)

That's the point. Just a couple of awk statements do the trick, but we'll wait for the response about the "homework" issue! ;)

Rode 08-30-2009 09:23 AM

Quote:

Originally Posted by colucix (Post 3662797)
Welcome to LinuxQuestions! :)

What is the purpose of this script? Homework? How many lines it contains? If it is a very large file (I mean yours posted above is just an example) I'd start by splitting the file using split, so that it is far more easy to manage couples of values.

Thank you for reply.
In fact, I'm not familiar with linux at all, it's just an assignment by my boss, this is the simple case. The number of lines in real case is variable, but here, I just appreciate an awk program example from you so I may try the similar way to do something more. As you mentioned, splitting into two inputfiles might be more convenient. I did consider that but got no solution due to poor command of it. If you give me an example referring to two inputfiles it will be helpful.

Thanks.

Rode 08-30-2009 09:33 AM

Quote:

Originally Posted by pixellany (Post 3662812)
Give us an example of what you have tried---and: Why you want to use Awk?

Since BASH does not support non-integer math, you will need a utility like "bc"---or maybe just use Python.

Thank you for suggestion, it's pity i know nothing but the name of python

pixellany 08-30-2009 09:34 AM

Quote:

it's just an assignment by my boss
What is your job, and what kinds of things are you expected to know?

Our rules and policies about homework can logically also apply to helping you with your job assignments-----If you are expected to know how to do certain things, we will be doing you a disservice by doing them for you. If you are going to get more assignments like this, then we need to help you learn ALL of the relevant tools.

SO....please tell us more about what kind of work you are doing...and more about the context of this particular question.

Rode 08-30-2009 09:55 AM

Quote:

Originally Posted by pixellany (Post 3662849)
What is your job, and what kinds of things are you expected to know?

Our rules and policies about homework can logically also apply to helping you with your job assignments-----If you are expected to know how to do certain things, we will be doing you a disservice by doing them for you. If you are going to get more assignments like this, then we need to help you learn ALL of the relevant tools.

SO....please tell us more about what kind of work you are doing...and more about the context of this particular question.

Don't worry about it too much. it's not that serious. I'm sorry it's not an easy job to tell you the entire assignment. I just put the simple case of the trouble I met, and I do not have too much time to learn awk. So what i need is a quick start, from the example solutions you possibly give me, and i try the similar way. If other questions raise, ask again.
If any ambiguous expression occured, i apologize.
Thanks again

catkin 08-30-2009 10:58 AM

A couple of good awk pages: GNU awk manual and Grymoire.

The ethos on LQ is to help people who have tried and got stuck or who have specific questions. There are a couple of reasons for that. Firstly questioners learn more if they try for themselves and secondly we are more inclined to spend time answering questions if the questioner has spent some time themselves.

pixellany 08-31-2009 09:36 AM

Quote:

Originally Posted by Rode (Post 3662868)
Don't worry about it too much. it's not that serious. I'm sorry it's not an easy job to tell you the entire assignment. I just put the simple case of the trouble I met, and I do not have too much time to learn awk. So what i need is a quick start, from the example solutions you possibly give me, and i try the similar way. If other questions raise, ask again.
If any ambiguous expression occured, i apologize.
Thanks again

The way that this comes across---you simply want us to do the assignment for you.

I did not ask you to describe the entire assignment---just give us the context.

In the interests of trying to help you for the long run, I really want to know if you are in a situation where you are expected to know how to do this.

If you do not want to provide any information, that's OK---but it certainly reduces your chances of getting any help here.


All times are GMT -5. The time now is 04:10 AM.