intersect data and name them accordingly - Awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting intersect data and name them accordingly - Awk
# 1  
Old 08-13-2010
intersect data and name them accordingly - Awk

input1

Code:
a1	1	10	1E_gx007
a1	20	30	2E_gx007
a1	50	60	3E_gx007

input2

Code:
a1	8	10	J1	100	gx007
a1	20	22	J1	120	gx007
a1	6	10	J2	200	gx007
a1	52	54	J2	220	gx007
a1	28	30	J3	300	gx007
a1	50	54	J3	320	gx007

output

Code:
a1	1	10	1E_gx007	a1	8	10	J1	100	gx007	2	connected
a1	20	30	2E_gx007	a1	20	22	J1	120	gx007	2	connected
a1	1	10	1E_gx007	a1	6	10	J2	200	gx007	2	notconnected
a1	50	60	3E_gx007	a1	52	54	J2	220	gx007	2	notconnected
a1	20	20	2E_gx007	a1	28	30	J3	300	gx007	2	connected
a1	50	60	3E_gx007	a1	50	54	J3	320	gx007	2	connected


if the 1st and 4th columns (a1 and gx007(ignore 1E_)) of input1 are similar to 1st and 6th columns of input2 (a1 and gx007)
intersect values of 2nd and 3rd columns of input1 (1 and 10) with all the values of 2nd and 3r columns of input2 and print
them in output with a specific name "connected" if they joined together (ex:1E_gx007-2E_gx007-2E_gx007-3E_gx007) and if not
"disconnected" (1E_gx007-3E_gx007)

And 11th column in output came from values of 5th column of input2 after a simple calculation. that is
connected values/connected+disconnected vaues i.e. ((100+120)+(300+320)) / (200+220) = 2

Hope evry thing is clear enough. Pardon if there is anothing confusing. Please let me know if trouble understanding the question
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk for streaming data - if/then

Hello, I've written an awk one-liner to parse a stream of real-time data. I invoke a program that gives me output from which I extract a few columns, perform some simple calculations, and then stream that data into a portal using an http string. It's tricky because I have to run it every second... (2 Replies)
Discussion started by: jm4smtddd
2 Replies

2. Shell Programming and Scripting

Splitting the Data using awk

Hello All, I have a comma delimiter file with 10 columns. I took the desired data but from $4 I need to split into two columns as 3+7 bytes. awk -F"," -v OFS=',' '{print $2,$3,$4}' foo.txt 42366,11/10/2014,5012418769 42366,11/10/2014,2046955672 42366,11/10/2014,2076802951 ... (3 Replies)
Discussion started by: karumudi7
3 Replies

3. Shell Programming and Scripting

awk --> math-operation in data-record and joining with second file data

Hi! I have a pretty complex job - at least for me! i have two csv-files with meassurement-data: fileA ...... (2 Replies)
Discussion started by: IMPe
2 Replies

4. UNIX for Dummies Questions & Answers

Intersect of two columns in two separate files

Hi, I have a file like this: abc def ghi jkl mno My second file is like this (tab delimited): adsad sdfsdf dfdf wads abc dfdsf sdsf jkl sfsdf dsfds sdfd reor zxczd dsf sff Now, I want the code to report the lines (from file2) which have common strings in column 2 with the first... (4 Replies)
Discussion started by: a_bahreini
4 Replies

5. Shell Programming and Scripting

Help with parsing data with awk , eliminating unwanted data

Experts , Below is the data: --- Physical volumes --- PV Name /dev/dsk/c1t2d0 VG Name /dev/vg00 PV Status available Allocatable yes VGDA 2 Cur LV 8 PE Size (Mbytes) 8 Total PE 4350 Free PE 2036 Allocated PE 2314 Stale PE 0 IO Timeout (Seconds) default --- Physical volumes ---... (5 Replies)
Discussion started by: rveri
5 Replies

6. Shell Programming and Scripting

extract data with awk

i have a following output file PF Release 2.4 on SERVICE at Mon Feb 6 18:41:02 2012 ---------------------------------------- ---------------- |pPF |SEP |CAPS |CALLS |OPEN | |-------------------------------------------------------------| | 0 ---... (1 Reply)
Discussion started by: gauravah
1 Replies

7. 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

8. Shell Programming and Scripting

Computing data in awk

Hello, I am a newbie in programing. I want to compute the following in awk. I have the following data file: ID Value1 Value2 Value3 sade 0.21 0.45 23 foly 0.31 0.34 43 jude 0.40 0.11 63 jude 0.53 0.32 34 sade 0.67 0.49 66 foly 0.30 0.20 56 I want to take an ID “sade” , then take its... (6 Replies)
Discussion started by: ubeejani
6 Replies

9. Shell Programming and Scripting

Awk: Data Insert

Hi guys, I'm having some difficulties in insert some details to the following contents. I need to insert "TEST" under MIR & a value "25" to the next line. So far, I am able to insert "TEST" by using awk to capture MIR as the identifier. However, I am having some difficulties in inserting "25"... (3 Replies)
Discussion started by: nantheless
3 Replies

10. Shell Programming and Scripting

help reformat data with awk

I am trying to write an awk program to reformat a data table and convert the date to julian time. I have all the individual steps working, but I am having some issues joing them into one program. Can anyone help me out? Here is my code so far: # This is an awk program to convert the dates from... (4 Replies)
Discussion started by: climbak
4 Replies
Login or Register to Ask a Question