LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-30-2009, 08:28 AM   #1
Rode
LQ Newbie
 
Registered: Aug 2009
Posts: 21

Rep: Reputation: 0
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.

Last edited by Rode; 08-30-2009 at 08:31 AM.
 
Old 08-30-2009, 08:45 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.

Last edited by colucix; 08-30-2009 at 08:52 AM.
 
Old 08-30-2009, 08:59 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.
 
Old 08-30-2009, 09:02 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by pixellany View Post
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!
 
Old 08-30-2009, 09:07 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by colucix View Post
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..
 
Old 08-30-2009, 09:09 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by pixellany View Post
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!
 
Old 08-30-2009, 09:23 AM   #7
Rode
LQ Newbie
 
Registered: Aug 2009
Posts: 21

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
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.

Last edited by Rode; 08-30-2009 at 09:27 AM.
 
Old 08-30-2009, 09:33 AM   #8
Rode
LQ Newbie
 
Registered: Aug 2009
Posts: 21

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pixellany View Post
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
 
Old 08-30-2009, 09:34 AM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.
 
Old 08-30-2009, 09:55 AM   #10
Rode
LQ Newbie
 
Registered: Aug 2009
Posts: 21

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pixellany View Post
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

Last edited by Rode; 08-30-2009 at 10:02 AM.
 
Old 08-30-2009, 10:58 AM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
Old 08-31-2009, 09:36 AM   #12
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by Rode View Post
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.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
E-Mail server discussion, to serve or not to serve? gankoji Linux - Server 8 08-05-2009 10:13 AM
awk program..using index() visitnag Linux - Newbie 9 08-24-2008 03:54 PM
awk program. a little query! indiancosmonaut Programming 7 07-05-2007 09:48 AM
Counting number of occurance in awk program sarajevo Programming 2 11-01-2006 10:31 AM
Trying to make my server program serve a webpage to Firefox calorie712 Programming 6 03-16-2006 11:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration