Sponsored Content
Top Forums Shell Programming and Scripting Help With Array Operations in AWK Post 302420015 by cold_Que on Monday 10th of May 2010 10:51:14 AM
Old 05-10-2010
Help With Array Operations in AWK

I have two files

file1
[
Code:
            A 2 4 6 8
            B 1 3 5 7
            C 1 3 5 7
            D 1 3 5 7
            E 1 3 5 7

file2
Code:
             C D E F G
           H I J  K L

I need to add field 1 of file1 to both field 2s of file2 and repeat the same on all the rows in file 1...... so the output should be

A+D
A+I
B+D
B+I.......ect

The code below is what I have, but there has to be a better way. You see I have to repeat the same command 5 times to account for the 5 rows in file1

Where: CONG[i,j] is a multideminsonal array of file1 and SA[i,j] is a multi-dimensional array of file2


Code:
awk ' { for (j=1;j<=NF;j++) {
         CONG[NR,j]=$j
                             }
        {getline < "'$SA'"}  { for (j=1;j<=NF;j++) {
                                 SA[NR,j]=$j      }
                             }
       {for (i=1;i<=NR;i++) {print SA[i,1],SA[i,2],CONG[1,2],CONG[1,5],CONG[1,5] + SA[i,2]}}
       {for (i=1;i<=NR;i++) {print SA[i,1],SA[i,2],CONG[2,2],CONG[2,5],CONG[2,5] + SA[i,2]}}
       {for (i=1;i<=NR;i++) {print SA[i,1],SA[i,2],CONG[3,2],CONG[3,5],CONG[3,5] + SA[i,2]}}
       {for (i=1;i<=NR;i++) {print SA[i,1],SA[i,2],CONG[4,2],CONG[4,5],CONG[4,5] + SA[i,2]}}
       {for (i=1;i<=NR;i++) {print SA[i,1],SA[i,2],CONG[5,2],CONG[5,5],CONG[5,5] + SA[i,2]}}
      }' | sort -u |

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK help. how to compare a variable with a data array in AWK?

Hi all, i have a data array as follows. array=ertfgj2345 array=456ttygkd . . . array=errdjt3235 so number or elements in the array can varies depending on how big the data input is. now i have a variable, and it is $1 (there are $2, $3 and so on, i am only interested in $1). ... (9 Replies)
Discussion started by: usustarr
9 Replies

2. Shell Programming and Scripting

awk command: column operations

I have a txt file with two columns Freq Loss 10 30 20 40 30 10 40 50 50 60i have used the below code to get the minimum value out of this array in second cloumn. awk 'NR==N{min=$N;max=$N}NR>N{if ($N>max){max=$N};if ($N<min){min=$N}}END {print... (3 Replies)
Discussion started by: shashi792
3 Replies

3. UNIX for Advanced & Expert Users

Array Operations in tcl

I would like to create an array using tcl script which takes in name, id, and marks of many people in 3 subjects. I would like calculate the total marks of each person and rank them according to their marks. Taking name as my key for access i want to do sort and rank the person based on highest... (3 Replies)
Discussion started by: Carlton
3 Replies

4. Shell Programming and Scripting

sh array and awk help...

Hi, I'm newbie with shell scripting and I'm in trouble with this: prenotazioni=/root/script/dhcp/prenotazioni.txt file=/root/script/dhcp/listaage.txt for nomefile in $(cut -d: -f1 $file); do ind=3 while do comando="$"$ind option=$(grep $nomefile $prenotazioni | awk... (2 Replies)
Discussion started by: gua76
2 Replies

5. Shell Programming and Scripting

Arthmetic & Operations Using AWK

Trying to do math while using awk and if statements. awk 'BEGIN {FS = ":"} ; {if($2=1) {$3 +=}; print "Total employee work hours: " $3}' works_on.txt The file format is 123456789:1:32.5 123456789:2:7.5 666884444:3:40.0 453453453:1:20.0 453453453:2:20.0 333445555:2:10.0 ... (6 Replies)
Discussion started by: Rapcher
6 Replies

6. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

7. Shell Programming and Scripting

Array from awk

I'm trying to get the output from awk into a bash array. Here is my script. #!/bin/bash while : do app=$( osascript -e "tell application \"System Events\" to return name of every process whose frontmost is true" ) echo "$app" if ava ]] then ps -ax | grep -v awk | pids=( $(awk... (5 Replies)
Discussion started by: nextyoyoma
5 Replies

8. Shell Programming and Scripting

awk - sed / reading from a data file and doing algebraic operations

Hi everyone, I am trying to write a bash script which reads a data file and does some algebraic operations. here is the structure of data.xml file that I have; 1 <data> 2 . 3 . 4 . 5 </data> 6 <data> 7 . 8 . 9 . 10</data> etc. Each data block contains same number of lines (say... (4 Replies)
Discussion started by: hayreter
4 Replies

9. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies

10. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies
h5diff(1)						      General Commands Manual							 h5diff(1)

NAME
h5diff - Compares two HDF5 files and reports the differences. SYNOPSIS
h5diff file1 file2 [OPTIONS] [object1 [object2 ] ] DESCRIPTION
h5diff is a command line tool that compares two HDF5 files, file1 and file2, and reports the differences between them. Optionally, h5diff will compare two objects within these files. If only one object, object1, is specified, h5diff will compare object1 in file1 with object1 in file2. In two objects, object1 and object2, are specified, h5diff will compare object1 in file1 with object2 in file2. These objects must be HDF5 datasets. object1 and object2 must be expressed as absolute paths from the respective file's root group. Additional information, with several sample cases, can be found in the document H5diff Examples. OPTIONS
file1 file2 The HDF5 files to be compared. -h Print all differences. -r Print only the names of objects that differ; do not print the differences. These objects may be HDF5 datasets, groups, or named datatypes. -n count Print difference up to count differences, then stop. count must be a positive integer. -d delta Print only differences that are greater than the limit delta. delta must be a positive number. The comparison criterion is whether the absolute value of the difference of two corresponding values is greater than delta (e.g., |a-b| > delta, where a is a value in file1 and b is a value in file2). -p relative Print only differences that are greater than a relative error. relative must be a positive number. The comparison criterion is whether the absolute value of the difference 1 and the ratio of two corresponding values is greater than relative (e.g., |1-(b/a)| > relative where a is a value in file1 and b is a value in file2). object1 object2 Specific object(s) within the files to be compared. EXAMPLES
The following h5diff call compares the object /a/b in file1 with the object /a/c in file2: h5diff file1 file2 /a/b /a/c This h5diff call compares the object /a/b in file1 with the same object in file2: h5diff file1 file2 /a/b And this h5diff call compares all objects in both files: h5diff file1 file2 SEE ALSO
h5dump(1), h5ls(1), h5repart(1), h5import(1), gif2h5(1), h52gif(1), h5perf(1) h5diff(1)
All times are GMT -4. The time now is 10:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy