LinuxQuestions.org
Review your favorite Linux distribution.
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 12-20-2012, 10:44 AM   #1
astroumut
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Rep: Reputation: 0
Multiplying two files where one file have only one cell with awk


Hi All,

I have two files. First file has one column with numbers and second file have only one number. I just want to do a simple multiplication with awk one-lines or any other useful commands.

I would be glad if you could help me on this.
Thanks

file 1
Code:
23
11
43
12
file 2
Code:
1.2
The output supposed to be

Code:
27.6
13.2
51.6
14.4
 
Old 12-20-2012, 10:50 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You have many possibilities. In awk you can try:
Code:
awk 'NR == FNR{factor=$0} NR > FNR{print $0*factor}' file2 file1
(where the order of the argument is important) or
Code:
awk -v factor=$(<file2) '{print $0*factor}' file1
Hope this helps.
 
1 members found this post helpful.
Old 12-20-2012, 10:56 AM   #3
astroumut
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Dear colucix,

Thanks a lot, it works like a charm.
 
  


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
Rename files using csv file and awk tuxlux Programming 6 09-03-2013 08:46 PM
How to split a file into multiple files using AWK? keenboy Linux - General 1 08-05-2010 02:18 PM
Split large file in several files using scripting (awk etc.) chipix Programming 14 10-29-2007 12:16 PM
Multiplying data column in awk - can rounding be suppressed? johnpaulodonnell Linux - Newbie 2 02-28-2007 08:56 AM
OO.org calc not multiplying my excel file np complete Linux - Software 0 10-15-2004 11:14 AM


All times are GMT -5. The time now is 11:03 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