Compare files with fields separated with semicolon


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare files with fields separated with semicolon
# 1  
Old 07-16-2011
Compare files with fields separated with semicolon

Dear experts

I have files like
Code:
ABD : 5869 events, relative ratio : 1.173800E-01 , sum of ratios : 1.173800E-01 
VBD : 12147 events, relative ratio : 2.429400E-01 , sum of ratios : 3.603200E-01 
SDF : 17000 events, relative ratio : 3.400000E-01 , sum of ratios : 7.003200E-01 
OIP: 14984 events, relative ratio : 2.996800E-01 , sum of ratios : 1.000000E+00

so, the values I want to compare are separated with a ':' followed by a space -- I want to use file1 as reference, and compare file2 value by value and line by line but comparing only columns 2,3 etc until the end of each line, and if I have a mismatch by a certain ratio (valueA/valueB) while comparing each given column on each given line do something, (actionA) otherwise do actionB

Thanks in advance

Last edited by Franklin52; 07-17-2011 at 06:33 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 07-17-2011
Hint

awks and associative arrays
or try in perl, you will have greater control
# 3  
Old 07-17-2011
an example would be greatly appreciated..

thanks!
# 4  
Old 07-17-2011
It sure would! Your input is rather vague.

Code:
awk 'NR==FNR { a[$0]++; next }
($0 in a) { do stuff }'

This puts first1 into an array, then looks for each line of file2 inside of the array.. I am not sure what columns you mean to compare. All of them, it sounds like, individually?? And is that first column the one that should be used to actually compare data between the two files? Like, compare the numbers for ABD in file1 only to the numbers for ABD in file2? ...

Edit: Best way to show us is a small file1 and file2 example, with desired output.
# 5  
Old 07-17-2011
thanks for the reply

Sorry if I was not clear -- I want to compare 1rst field after the first ':' from file1 with 1rst field after the fist ':' from file2 , then the same for the second fields etc etc on a line - by - line basis
# 6  
Old 07-17-2011
So, you want to compare line1 of file1 to line1 of file2. You calculate a delta ratio between the two and perform an action whether they're within range or not?
# 7  
Old 07-17-2011
yep, exactly this! -- in each line, the value I want to compare starts after the ": " ,so is a 1-to-1 comparison

Can you provide a script?

thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is there a UNIX command that can compare fields of files with differing number of fields?

Hi, Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account. $ head -500 x.txt y.txt ==> x.txt <== TEST01 APP_USER_PROFILE USER03 APP_USER_PROFILE TEST02 APP_USER_EXP_PROFILE TEST04 APP_USER_PROFILE USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. Shell Programming and Scripting

Compare fields in two files

Hi, I am trying to check two files based on certain string and field. cat f1 source=\GREP\" hi this \\ source=\SED\" skdmsmd dnksdns source=\PERL\" cat f2 source=\SED\" source=\GREP\" vlamskds amdksk m source=\AWK\" awk \here\" (3 Replies)
Discussion started by: greet_sed
3 Replies

3. UNIX for Dummies Questions & Answers

Compare 2 fields in 2 files

I am trying to compare two files (separted by a pipe) using 2 fields (field 1,3 from fileA and 1,2 from fileB) if the two files match i want the whole record of fileA adding the extra fields left from fileB. 1. A.txt cat|floffy|12|anything|anythings cat|kitty|15|lala|lalala... (6 Replies)
Discussion started by: sabercats
6 Replies

4. Shell Programming and Scripting

grep lines separated with semicolon

Hello, I would like to kindly ask you for help. I have a file with some lines in one row separated by semicolon. I need to find out, if the line I have in different variable is included in this file. e.g I have a file foo.txt with lines A=hello there;hello world;hello there world In... (6 Replies)
Discussion started by: satin1321
6 Replies

5. Shell Programming and Scripting

AWK:Split fields separated by semicolon

Hi all, I have a .vcf file which contains 8 coulmns and the data under each column as shown below, CHROM POS ID REF ALT QUAL FILTER INFO 1 3000012 . A G 126 ... (6 Replies)
Discussion started by: mehar
6 Replies

6. Shell Programming and Scripting

Compare fields in files

Hi, I need the most efficient way of comparing the following and arriving at the result I have a file which has entries like, File1: 1|2|5|7|8|2|3|6|3|1 File2: 1|2|3|1|2|7|9|2 I need to compare the entries in these two file with those of a general file, 1|2|3|5|2|5|6|9|3|1... (7 Replies)
Discussion started by: pradebban
7 Replies

7. Shell Programming and Scripting

compare fields in different files

HI I'm having some troubles to compare and permut diffrent fields indexed with another filed like the following example `: file1 1 1 2 2 3 3 file2 7 1 9 2 10 3 result------------------- (6 Replies)
Discussion started by: yassinegoth
6 Replies

8. Shell Programming and Scripting

Compare Tab Separated Field with AWK to all and print lines of unique fields.

Hi. I have a tab separated file that has a couple nearly identical lines. When doing: sort file | uniq > file.new It passes through the nearly identical lines because, well, they still are unique. a) I want to look only at field x for uniqueness and if the content in field x is the... (1 Reply)
Discussion started by: rocket_dog
1 Replies

9. Shell Programming and Scripting

Extract semicolon separated delimiter

The log reads as follows. fname1;lname1;eid1;addr;pincode1; fname2;lname2;eid2;addr2;pincode2; fname3;lname3;eid3;addr3;pincode3; fname4;lname4;eid;addr4;pincode4; how do i extract only fname and save it in an array similarly for lname and so on i tried reading a file and cutting each... (5 Replies)
Discussion started by: vkca
5 Replies

10. Shell Programming and Scripting

Compare semicolon seperated data in 2 files using shell script

hello members, I have some data ( seperated by semicolon ) with close to 240 rows in a text file temp1. temp2.txt stores 204 rows of data ( seperated by semicolon ). I want to : Sort the data in both files by field1.i.e first data field in every row. compare the data in both files and print... (6 Replies)
Discussion started by: novice82
6 Replies
Login or Register to Ask a Question