LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-16-2011, 10:34 PM   #1
Alkass
Member
 
Registered: Mar 2010
Posts: 47

Rep: Reputation: 0
compare files with fields separated with ':'


Dear experts

I have files like

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
Edit/Delete Message
 
Old 07-17-2011, 12:31 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Awk is the tool you'll want to use here. Or else a general text-processing language like perl.

Here are a few useful awk references:
http://www.grymoire.com/Unix/Awk.html
http://www.gnu.org/software/gawk/man...ode/index.html
http://www.informatik.uni-hamburg.de.../gawk_toc.html
http://www.pement.org/awk/awk1line.txt
http://www.catonmat.net/blog/awk-one...ined-part-one/


You'll have to be more specific about your exact goals if you want any detailed help.


And please use [code][/code] tags around your code, to preserve formatting and to improve readability.
 
Old 07-17-2011, 09:04 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Perl is pretty good at that sort of thing; here's some useful links http://perldoc.perl.org/ http://www.perlmonks.org/?node=Tutorials
 
Old 07-18-2011, 03:54 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
we need...

example files, expected output.


Then we can probably help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Compare two fields, then sort based on result. C.L. Programming 7 09-28-2010 09:43 AM
Getting all the files modified today & store the names in a variable as , separated ananthi_ku Linux - Newbie 3 04-27-2009 05:01 AM
Compare two fields on consecutive rows and print the two rows aditi_borkar Linux - Newbie 3 04-09-2009 05:49 AM
Parsing a comma separated CSV file where fields have commas in to trickyflash Linux - General 7 03-26-2009 03:30 PM
reading fields from files in python without \t \n dumpthecore Programming 1 12-11-2003 04:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration