LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 09-01-2010, 12:24 AM   #1
mauludi
LQ Newbie
 
Registered: Jan 2010
Posts: 21

Rep: Reputation: 0
How to make arithmetic operation of data file with script file?


Dear All,

I wonder how to arithmetic operation of our data file using any script program/command (like sed, cut,awk)for example my data.file is:

45 65 42
12 23 61
43 34 21

I want to multiply first column with 2 and add second column with 3 then it become

90 68 42
24 26 61
86 37 21

thank you very much in advance

with best regards,
ludi
 
Old 09-01-2010, 12:57 AM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 805

Rep: Reputation: 186Reputation: 186
I think awk will.

What you have to do is for each line, multiply the first column by 2, add 3 to the second column, display the third and any other columns as they are. What did you try?

End
 
Old 09-01-2010, 01:04 AM   #3
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
This is not at all difficult and can easily be figure out searching around. I'm normally not one to suggest Google searches, but this smells a lot like homework. I looked at a few of your other posts and they are very similar. Searching/processing on simple data files. These all look like homework type work for beginning scripting classes.

A simple 'cut' and basic bash arithmetic is all you need.

http://www.linuxconfig.org/Bash_scripting_Tutorial
 
Old 09-01-2010, 02:02 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by mauludi View Post
Dear All,

I wonder how to arithmetic operation of our data file using any script program/command (like sed, cut,awk)for example my data.file is:

45 65 42
12 23 61
43 34 21

I want to multiply first column with 2 and add second column with 3 then it become

90 68 42
24 26 61
86 37 21

thank you very much in advance

with best regards,
ludi
I'd personally also go with awk.


Cheers,
Tink
 
Old 09-01-2010, 02:33 AM   #5
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
Assuming that you have covered awk in your course, this should be a one liner.

HINT:- you need to use the print function
 
Old 09-01-2010, 06:26 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Quote:
HINT:- you need to use the print function
Well not literally required
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Script for pulling data out of a txt file schapman43 Linux - Newbie 7 08-03-2010 02:07 PM
Arithmetic operation with awk fugitive569 Programming 2 12-04-2009 11:10 AM
display after arithmetic operation tostay2003 Programming 7 08-14-2008 12:51 PM
use script to create a data file of mulitple users RajRed Linux - Newbie 4 11-27-2007 07:05 PM
How to read data from file to use in shell script? ozymandias Linux - Newbie 7 10-27-2006 02:19 PM


All times are GMT -5. The time now is 08: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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration