Complex overlap and naming of 2 input files - Awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Complex overlap and naming of 2 input files - Awk
# 1  
Old 08-25-2010
Complex overlap and naming of 2 input files - Awk

for every specific $1,$2 check the values ($2,$3) of their E ot I of input1 and overlap with input2.

Specify names based on output.
#######
if middle value is missing name them "SE"
if first value is missing name them "AFE"
if last value is missing name them "ALE"
if 2 middle values are missing name them "MXE"
if 1st value is shorter but still overlapping then name "A5SS"
if last value is shorter but stil overlapping then name "A3SS"

Examples

if middle value is missing in input2 name them "SE"
###################################################

input1
a1 100 200 E1 ABC
a1 300 400 E2 ABC
a1 500 600 E3 ABC

input2
a1 100 200 E1 ABC
a1 500 600 E3 ABC

output
a1 300 400 E2 ABC SE


input1

Code:
a1	100	200	E1	ABC
a1	300	400	E2	ABC
a1	500	600	E3	ABC
a2	100	200	E1	CDE
a2	300	400	E2	CDE
a2	500	600	E3	CDE
a3	100	200	E1	EFG
a3	300	400	E2	EFG
a3	500	600	E3	EFG
a4	100	200	E1	DEF
a4	300	400	E2	DEF
a4	500	600	E3	DEF
a4	700	800	E4	DEF
a5	100	200	E1	GHI
a5	200	300	I1	GHI
a5	300	400	E2	GHI
a1	100	200	E1	IJK
a1	300	400	E2	IJK
a2	100	200	E1	IJK
a2	300	400	E2	IJK
a1	100	200	E1	PQR
a1	300	400	E2	PQR
a1	500	600	E3	PQR
a1	800	900	E4	PQR

input2
Code:
a1	100	200	E1	ABC
a1	500	600	E3	ABC
a2	300	400	E2	CDE
a2	500	600	E3	CDE
a3	100	200	E1	EFG
a3	300	400	E2	EFG
a4	100	200	E1	DEF
a4	700	800	E4	DEF
a5	100	200	E1	GHI
a5	300	400	E2	GHI
a1	100	170	E1	IJK
a1	300	400	E2	IJK
a2	100	200	E1	IJK
a2	270	400	E2	IJK
a1	100	200	E1	PQR
a1	300	400	E2	PQR
a1	800	900	E4	PQR

output

Code:
a1	300	400	E2	ABC	SE
a2	100	200	E1	CDE	AFE
a3	500	600	E3	EFG	ALE
a4	300	400	E2	DEF	MXE
a4	500	600	E3	DEF	MXE
a5	200	300	I1	GHI	IR
a1	100	170	E1	IJK	A5SS
a2	270	400	E2	IJK	A3SS
a1	500	600	E3	PQR	SE


Note: it should be the same even though it is not just 1st value but the pattern is same in other values (Ex: check PQR)

Hope I explained clear enough

Thanx
ruby
# 2  
Old 08-25-2010
The phrasing sounds like classroom stuff. You got a PM how and where to post classroom stuff - closed.
This User Gave Thanks to zaxxon For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Naming output files based on variable parameters and input filenames

Hello, I have a series of files in sub-directories that I want to loop through, process and name according to the input filename and the various parameters I'm using to process the files. I have a number of each, for example file names like AG005574, AG004788, AG003854 and parameter values like... (2 Replies)
Discussion started by: bdeads
2 Replies

2. Shell Programming and Scripting

Complex match of numbers between 2 files awk script

Hello to all, I hope some awk guru could help me. I have 2 input files: File1: Is the complete database File2: Contains some numbers which I want to compare File1: "NUMBERKEY","SERVICENAME","PARAMETERNAME","PARAMETERVALUE","ALTERNATENUMBERKEY"... (9 Replies)
Discussion started by: Ophiuchus
9 Replies

3. UNIX for Dummies Questions & Answers

naming files in awk

I have a whole directory and I need each lines of each file to be separated to a new file but I am facing problem naming them :( some of the files even might be empty the output files should be names original file name + the number of the line or any incremental number FILES="data/*" for X in... (12 Replies)
Discussion started by: A-V
12 Replies

4. Shell Programming and Scripting

Get values from 2 files - Complex "for loop and if" awk problem

Hi everyone, I've been thinking and trying/changing all day long the below code, maybe some awk expert could help me to fix the for loop I've thought, I think I'm very close to the correct output. file1 is: <boxes content="Grapes and Apples"> <box No.="Box MT. 53"> <quantity... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

5. Shell Programming and Scripting

AWK using two input files

Hi , i have two input files one is input.gz and another is ( input.txt) text file.in gz format input file each record contains 10 fields and corresponding header value is present in the text file as a single record i.e text file contains only 10 records which is header value,so output of the awk... (1 Reply)
Discussion started by: Ajoy
1 Replies

6. Shell Programming and Scripting

Awk Overlap

Based on input1 specific key (column1, 4 and 5) take the values (column 2 and 3) overlap with input2. And Specify names based on output. input1 a1 100 200 E1 ABC a1 300 400 E2 ABC a1 500 600 E3 ABC a2 100 200 E1 CDE a2 300 400 E2 ... (2 Replies)
Discussion started by: ruby_sgp
2 Replies

7. UNIX for Advanced & Expert Users

Complex Input/Output Redirect

Hi All, Sorry if the title is not good but I did not know how to explain with only some words! What I meant is: I have a unix command built from a private application vendor that when executed it prompts for two entries by the keyboard, let's say, for example: ... (1 Reply)
Discussion started by: felipe.vinturin
1 Replies

8. Shell Programming and Scripting

awk merging files based on 2 complex conditions

1. if the 1st row IDs of input1 (ID1/ID2.....) is equal to any IDNames of input2 print all relevant values together as defined in the output. 2. A bit tricky part is IDno in the output. All we need to do is numbering same kind of letters as 1 (aa of ID1) and different letters as 2 (ab... (4 Replies)
Discussion started by: ruby_sgp
4 Replies

9. Shell Programming and Scripting

Splitting input files into multiple files through AWK command

Hi, I needs to split *.txt files from single directory depends on the some mutltiple input values. i have wrote the code like below for file in *.txt do grep -i -h "value1|value2" $file > $file; done. My requirment is more input values needs to be given in grep; let us say 50... (3 Replies)
Discussion started by: arund_01
3 Replies

10. Shell Programming and Scripting

2 input files for awk

Hi, i have 2 files like f1 and f2 f1: 1 Note: some times it will be cahnged to 2 and 3. f2: 1:20 2:30 4:50 6:70 8:90 3:20 1:30 1:40 output: 1:80 (sum of 1) (6 Replies)
Discussion started by: koti_rama
6 Replies
Login or Register to Ask a Question