Sponsored Content
Top Forums UNIX for Dummies Questions & Answers using awk or shell for multplication Post 302156440 by cdfd123 on Tuesday 8th of January 2008 06:23:11 AM
Old 01-08-2008
using awk or shell for multplication

Suppose if u have a file like that
file1
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002
etc..

another file
file2
1.2
3.2
-3.4
2.3
2.5
3.4
2.5
3.7
-4.5
2.4

So want to have each one in a file 1 multiply with another one in file 2 respectively
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002 ----->multiply by 1.2
0.01*0.02*0.04*0.06*0.03*0.05*0.04*0.009*0.002 ----->multiply by 3.2.
respectively......
That is want output to be like below
0.012*0.024*0.048*0.072*0.036*0.06*0.048*0.0108*0.0024
.....
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

shell / awk doubt

Hi all, I have a ascii text file like this : $cat a.txt abc |12343 |xyakdfj | x |323 || kr1 |13434343|234343 | Is it possible to to get the file eleminating blank spaces? output file : abc|12343|xyakdfj| x|323||... (7 Replies)
Discussion started by: krishna
7 Replies

2. Shell Programming and Scripting

Using shell variables In awk

Oh its not my day for syntax... cat gzipsize.txt | awk '{print "echo",$1,$2} > master.txt I have read a lot about the awk -v but haven't been able to get it to work. I have a variable in my script and I'm looking just to push it into the awk after the $2 (or anywhere would do)!!! Every... (11 Replies)
Discussion started by: nortypig
11 Replies

3. UNIX for Advanced & Expert Users

AWK instead of Shell script

I've a list file, which has some file names. ex: list file "list_file" will have data_file1.txt data_file2.txt data_file3.txt : : data_filen.txt Above files will have the below layout: Header1 Header2 *TM* Data record 1 Datarecord 2 Datarecord n *TM* (19 Replies)
Discussion started by: Lokesha
19 Replies

4. Shell Programming and Scripting

shell / awk arrays

I have a bash shell script that sources a data file, the data file has array values such as: #--data file ---# sg_name="db1" sg_size="12892" sg_allow="50000" sg_name="db2" sg_size="12892" sg_allow="50000" export sg_name sg_size sg_allow #--end data file --# In my shell script... (8 Replies)
Discussion started by: lochraven
8 Replies

5. Shell Programming and Scripting

Shell Script using awk

File1 9000|9000|WW|1|1|SL|472|472|LC|2272|1072|MTY 9000|9000|WW|1|1|SL|470|470|MC|1270|1172|MPVT 9000|9000|WW|1|1|SL|472|472|LC|1072|1672|MBD 9000|9000|WW|1|1|SL|473|473|LF|1173|1173|MTY File2 DPT.1072 CP~ Apr 1514283.914 (12 Replies)
Discussion started by: yale_work
12 Replies

6. Shell Programming and Scripting

shell command in AWK

Hi experts, Sorry if it sounds basic question. I am trying to delete all folders except a particular and I have written the following. But its not deleting the folder. Could you tell me whats wrong? folders are: 1 2 3 4 5 6 ls -l | awk '{ if ($9 != 4) {system(/bin/rmdir $9);print... (5 Replies)
Discussion started by: amitrajvarma
5 Replies

7. Shell Programming and Scripting

Shell variable in awk

I have 3 files and each contain m*n matrix. m = number of rows (horizontal lines) n = number of columns (entries in a particular line) What I wish to find is the sum of the 2nd number in the last row. Ex file1.dat 2 5 8 8 4 6 7 8 3 8 3 7 file2.dat 3 4 1 4 8 4 0 3 4 7 3 7 ... (3 Replies)
Discussion started by: dynamics
3 Replies

8. Shell Programming and Scripting

awk loop and using shell in awk

Hi, everyone! I have a file, when I print its $1 out it show several strings like this: AABBCC AEFJKLFG FALEF FAIWEHF What I want to do is that, after output of each record, search the string in all files in the same folder, print out the record and file name. This is what I want... (4 Replies)
Discussion started by: xshang
4 Replies

9. Shell Programming and Scripting

Awk: How to get an awk variable out to the shell, using system() ?

I am reasonably capable with awk and its quirks, but not with shell weirdness. This has to be Bourne Shell for portability reasons. I have an awk program that is working just fine; it handles multiple input streams and produces several reports, based on the request (-v Variables). In addition... (3 Replies)
Discussion started by: DerekAsirvadem
3 Replies

10. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies
NATSORT(3)								 1								NATSORT(3)

natsort - Sort an array using a ";natural order" algorithm

SYNOPSIS
bool natsort (array &$array) DESCRIPTION
This function implements a sort algorithm that orders alphanumeric strings in the way a human being would while maintaining key/value associations. This is described as a "natural ordering". An example of the difference between this algorithm and the regular computer string sorting algorithms (used in sort(3)) can be seen in the example below. PARAMETERS
o $array - The input array. RETURN VALUES
Returns TRUE on success or FALSE on failure. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ |5.2.10 | | | | | | | Zero padded numeric strings (e.g., '00005') now | | | essentially ignore the 0 padding. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 natsort(3) examples demonstrating basic usage <?php $array1 = $array2 = array("img12.png", "img10.png", "img2.png", "img1.png"); asort($array1); echo "Standard sorting "; print_r($array1); natsort($array2); echo " Natural order sorting "; print_r($array2); ?> The above example will output: Standard sorting Array ( [3] => img1.png [1] => img10.png [0] => img12.png [2] => img2.png ) Natural order sorting Array ( [3] => img1.png [2] => img2.png [1] => img10.png [0] => img12.png ) For more information see: Martin Pool's Natural Order String Comparison page. Example #2 natsort(3) examples demonstrating potential gotchas <?php echo "Negative numbers "; $negative = array('-5','3','-2','0','-1000','9','1'); print_r($negative); natsort($negative); print_r($negative); echo "Zero padding "; $zeros = array('09', '8', '10', '009', '011', '0'); print_r($zeros); natsort($zeros); print_r($zeros); ?> The above example will output: Negative numbers Array ( [0] => -5 [1] => 3 [2] => -2 [3] => 0 [4] => -1000 [5] => 9 [6] => 1 ) Array ( [2] => -2 [0] => -5 [4] => -1000 [3] => 0 [6] => 1 [1] => 3 [5] => 9 ) Zero padding Array ( [0] => 09 [1] => 8 [2] => 10 [3] => 009 [4] => 011 [5] => 0 ) Array ( [5] => 0 [1] => 8 [3] => 009 [0] => 09 [2] => 10 [4] => 011 ) SEE ALSO
natcasesort(3), The comparison of array sorting functions, strnatcmp(3), strnatcasecmp(3). PHP Documentation Group NATSORT(3)
All times are GMT -4. The time now is 01:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy