Sponsored Content
Top Forums Shell Programming and Scripting Multiplication of two files and and sorting Post 302912301 by bharat1211 on Thursday 7th of August 2014 06:17:49 AM
Old 08-07-2014
Code:
file 1:                                               
AAAAA   3.465830E-12
BBBBB   4.263280E-08
CCCCC   1.113320E-17
DDDDD   0.000000E+00

file 2:

3.932350E-12
1.194380E-07
4.901480E-17
0.000000E+00

Script
Code:
awk 'FNR==NR{a[NR]=$1;next}{b[FNR]=$2;X[FNR]=$1;C=FNR;}
END{for(i=1;i<=C;i++)print X[i],a[i]"*"b[i]}' file2.txt file1.txt

output:
Code:
AAAAA 3.932350E-12*3.465830E-12
BBBBB 1.194380E-07*4.263280E-08
CCCCC 4.901480E-17*1.113320E-17
DDDDD 0.000000E+00*0.000000E+00

If it want to perform multiplication just remove double quotes at line 2 of below code:
Code:
awk 'FNR==NR{a[NR]=$1;next}{b[FNR]=$2;X[FNR]=$1;C=FNR;}
END{for(i=1;i<=C;i++)print X[i],a[i]*b[i]}' file2.txt file1.txt

This User Gave Thanks to bharat1211 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

sorting files

ok so I'm having major issues trying to figure this out: I have this program that I'm inputting the files in hte current directory which are image files...it spits out 5 line chunks describing the files... filename: (name of file) size: (100 x 200) arbitrary data arbitrary data arbitrary... (4 Replies)
Discussion started by: Infraredskies
4 Replies

2. Shell Programming and Scripting

Sorting Files

How to sort such files which contains records of varying length and varying lines? (With respect to Bash shell) Eg: Each record begins with a sting of 1/0(binary) which may or may not be followed by properties like AB,BS etc. I have to sort such records on the basis of 1/0 string and keep the... (2 Replies)
Discussion started by: sandeep_hi
2 Replies

3. Shell Programming and Scripting

sorting files

hi i have file like below: col1,col2,col3,col4 val1,val2,val3,val4 abc1,abc2,abc3,abc4 this is a 4 column file with 3 rows. i want to sort the file like.. first on col1, then on col2 and so ..on.. i want the sort order to be descending. Pls help.. Thnks Sumit (2 Replies)
Discussion started by: sumit207
2 Replies

4. UNIX for Dummies Questions & Answers

Matrix multiplication with different files

Hi, i have file1 which looks like: x1 y1 z1 x2 y2 z2 ...(and so on) and file2 which looks like: a11 a12 a13 a21 a22 a23 a31 a32 a33 and i want to replace file1 with the following values: x1' y1' z1' x2' y2' z2' ...(and so on) (2 Replies)
Discussion started by: ezitoc
2 Replies

5. Shell Programming and Scripting

i need help in sorting two files

i have file a 123 234 456 567 678 and file b 123|xxx|hhh|ppp or zzz 234|rrr|ttt|xxx 432|ttt|mmm|nnn 678|cft|byt|mop i want to compare file a to file b such that when each of the lines in file a can be found in file b column1 and also xxx or hhh or ppp or zzz can be... (12 Replies)
Discussion started by: blackzinga80
12 Replies

6. Shell Programming and Scripting

Sorting files

I have the following set of files and I want to order them according to the ascending values of the run: For example, doing ls -lrt *drw*.log gives n02-z30-sr65-rgdt0p25-dc0p08-4x3drw.log n02-z30-sr65-rgdt0p25-dc0p03-8x6drw.log n02-z30-sr65-rgdt0p25-dc0p01-8x6drw.log ... (18 Replies)
Discussion started by: kristinu
18 Replies

7. Shell Programming and Scripting

multiplication of two files based on the content of the first column

Hi, This is something that probably it is more difficult to explain than to do. I have two files e.g. FILE1 A15 8.3102E+00 3.2000E-04 A15 8.5688E+00 4.3000E-05 B13 5.1100E-01 1.9960E+00 B16 5.1100E-01 2.3000E-03 B16 8.6770E-01 1.0000E-07 B16 9.8693E-01 3.4000E-05... (4 Replies)
Discussion started by: f_o_555
4 Replies

8. Shell Programming and Scripting

Selective multiplication of two columns in two files

Hi again, I have two files e.g. file2 e.g. file1 BB152 6.279650E+02 AA124 6.279650E+02 AA124 6.0273E-01 9.7800E-01 AA124 6.3239E-01 9.7800E-04 AA124 6.4585E-01 7.3839E-02 BB152 6.6250E-01 2.4450E-04 BB152 7.0932E-01 1.3496E-02 CC124 7.1378E-01 2.2690E-02 CC124 7.2279E-01... (8 Replies)
Discussion started by: f_o_555
8 Replies

9. Shell Programming and Scripting

Complex data sorting in excel files or text files

Dear all, I have a complex data file shown below,,,,, A_ABCD_13208 0 0 4.16735 141044 902449 1293900 168919 C_ABCD_13208 0 0 4.16735 141044 902449 1293900 168919 A_ABCDEF715 52410.9 18598.2 10611 10754.7 122535 252426 36631.4 C_DBCDI_1353 0... (19 Replies)
Discussion started by: AAWT
19 Replies

10. Shell Programming and Scripting

Multiplication of a column from 2 files using awk

Hi, I have two files (file1.txt, file2.txt) in which, I would like to multiply all the values in file1 with the first row value of file2, file1 * second row value of file2, file1 * third row value of file2 and so on. Below are my sample data. file1.txt file2.txt ... (6 Replies)
Discussion started by: ida1215
6 Replies
ZDIFF(1)                                                      General Commands Manual                                                     ZDIFF(1)

NAME
zcmp, zdiff - compare compressed files SYNOPSIS
zcmp [ cmp_options ] file1 [ file2 ] zdiff [ diff_options ] file1 [ file2 ] DESCRIPTION
Zcmp and zdiff are used to invoke the cmp or the diff program on files compressed via gzip. All options specified are passed directly to cmp or diff. If only file1 is specified, it is compared to the uncompressed contents of file1.gz. If two files are specified, their con- tents (uncompressed if necessary) are fed to cmp or diff. The input files are not modified. The exit status from cmp or diff is pre- served. SEE ALSO
cmp(1), diff(1), zmore(1), zgrep(1), znew(1), zforce(1), gzip(1), gzexe(1) BUGS
Messages from the cmp or diff programs may refer to file names such as "-" instead of to the file names specified. ZDIFF(1)
All times are GMT -4. The time now is 04:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy