Sponsored Content
Top Forums Shell Programming and Scripting Multiplication of two files and and sorting Post 302912320 by drl on Thursday 7th of August 2014 10:39:43 AM
Old 08-07-2014
Hi.

Alternate methods:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate arithmetic combination of column data, awk, dm.
# For dm utility in |stat, see:
# http://hcibib.org/perlman/stat/

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C paste awk dm

pl " Input data files data1 data2, combined into data3:"
paste data1 data2 > data3
head data1 data2 data3

pl " Results, awk:"
awk '{print $1,$2*$3}' data3

pl " Results, |stat dm:"
dm s1 'x2*x3' < data3

exit 0

producing:
Code:
$ ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian 5.0.8 (lenny, workstation) 
bash GNU bash 3.2.39
paste (GNU coreutils) 6.10
awk GNU Awk 3.1.5
dm - ( local: ~/executable/dm, 2009-11-09 )

-----
 Input data files data1 data2, combined into data3:
==> data1 <==
AAAAA	3.465830E-12
BBBBB	4.263280E-08
CCCCC	1.113320E-17
DDDDD	0.000000E+00

==> data2 <==
3.932350E-12 
1.194380E-07 
4.901480E-17 
0.000000E+00 

==> data3 <==
AAAAA	3.465830E-12	3.932350E-12 
BBBBB	4.263280E-08	1.194380E-07 
CCCCC	1.113320E-17	4.901480E-17 
DDDDD	0.000000E+00	0.000000E+00 

-----
 Results, awk:
AAAAA 1.36289e-23
BBBBB 5.09198e-15
CCCCC 5.45692e-34
DDDDD 0

-----
 Results, |stat dm:
AAAAA	1.36289e-23
BBBBB	5.09198e-15
CCCCC	5.45692e-34
DDDDD	0

Add the sort as desired.

Best wishes ... cheers, drl
 

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
fmemcmp(3)						     Library Functions Manual							fmemcmp(3)

NAME
fmemcmp - fuzzy comparison of two memory areas SYNOPSIS
#include <fstrcmp.h> #define FSTRCMP_IDENTICAL #define FSTRCMP_THRESHOLD #define FSTRCMP_ERROR double fmemcmp(const void *data1, size_t size1, const void *data2, size_t size2); DESCRIPTION
The fmemcmp() function compares the two memory areas, the size1 bytes pointed to by data1 and the size2 bytes pointed to by data2. RETURN VALUE
The fmemcmp function returns a floating point value between 0.0 and FSTRCMP_IDENTICAL. A value of 0.0 means the memory areas are utterly un-alike. A value of FSTRCMP_IDENTICAL means the memory areas are identical. A value of more than FSTRCMP_THRESHOLD (it lies between 0.0 and FSTRCMP_IDENTICAL) would be considered "similar" by most people. A value of FSTRCMP_ERROR (always negative) indicates a malloc(3) failure. SEE ALSO
fmemcmpi(3) fuzzy comparison of two memory areas fstrcmp(3) fuzzy comparison of two strings memcmp(3) compare memory areas COPYRIGHT
fstrcmp version 0.4 Copyright (C) 2009 Peter Miller Peter Miller <pmiller@opensource.org.au> The comparison code is derived from the fuzzy comparison functions in GNU Gettext 0.17. The GNU Gettext comparison functions were, in turn, derived from GNU Diff 2.7. Copyright (C) 1988-2009 Free Software Foundation fmemcmp(3)
All times are GMT -4. The time now is 06:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy