Compare columns of 2 files based on condition defined in a different file
I have a control file which tells me which are the fields in the files I need to compare and based on the values I need to print the exact value if key =Y and output is Y , or if output is Y/N then I need to print only Y if it matches or N if it does not match and if output =N , then skip the feild to compare and write it to a output file
For ex:
my control file
I was trying to do it in 2 parts and then combine, but I am lost, need your help to combine this logic.
To compare the 2 files and print the output as Y or N
I can do then seperately, but I am not able to read the control file and compare the files based on the control file.
Please help me.
Thanks in Advance
newtoawk
Last edited by Scott; 11-07-2010 at 05:57 AM..
Reason: Please use code tags
Hi Experts,
Is there a way to compare 2 files by columns and print matching cases.
I have 2 files as below, I want cases where col1 and col2 in f1 matches col1 and col2 in f2 to be printed as output. The separator is space. I want the output to have col1 col2 col 3 from both files printed... (7 Replies)
hi
my problem is little complicated one. i have 2 files which appear like this
file 1
abbsss:aa:22:34:as akl abc 1234
mkilll:as:ss:23:qs asc abc 0987
mlopii:cd:wq:24:as asd abc 7866
file2
lkoaa:as:24:32:sa alk abc 3245
lkmo:as:34:43:qs qsa abc 0987
kloia:ds:45:56:sa acq abc 7805
i... (5 Replies)
I have a file named file.txt that looks as follows
//class1.txt
45
234
67
89
90
//class2.txt
456
34
78
89
120
class1 and class2.txt are the names of files in a folder named folder1.
The content of class1.txt file in folder1
67 9
89 5
234 9The content of class2.txt file in... (1 Reply)
Hi I have a matrix with n rows and m columns like below example. i want to extract all the pairs with values <200.
Input
A B C D
A 100 206 51 300
B 206 100 72 48
C 351 22 100 198
D 13 989 150 100
Output format
A,A:200
A,C:51
B,B:100... (2 Replies)
I have a file some thing like this:
GN Name=YWHAB;
RC TISSUE=Keratinocyte;
RC TISSUE=Thymus;
CC -!- FUNCTION: Adapter protein implicated in the regulation of a large
CC spectrum of both general and specialized signaling pathways
GN Name=YWHAE;
RC TISSUE=Liver;
RC ... (13 Replies)
Hi,
I want to compare two columns from file1 with another two column of file2 and print matched and unmatched column like this
File1
1 rs1 abc
3 rs4 xyz
1 rs3 stu
File2
1 kkk rs1 AA 10
1 aaa rs2 DD 20
1 ccc ... (2 Replies)
SORT(1) General Commands Manual SORT(1)NAME
sort - sort and/or merge files
SYNOPSIS
sort [ -cmuMbdfinrwtx ] [ +pos1 [ -pos2 ] ... ] ... [ -k pos1 [ ,pos2 ] ] ...
' [ -o output ] [ -T dir ... ] [ option ... ] [ file ... ]
DESCRIPTION
Sort sorts lines of all the files together and writes the result on the standard output. If no input files are named, the standard input
is sorted.
The default sort key is an entire line. Default ordering is lexicographic by runes. The ordering is affected globally by the following
options, one or more of which may appear.
-M Compare as months. The first three non-white space characters of the field are folded to upper case and compared so that precedes
etc. Invalid fields compare low to
-b Ignore leading white space (spaces and tabs) in field comparisons.
-d `Phone directory' order: only letters, accented letters, digits and white space are significant in comparisons.
-f Fold lower case letters onto upper case. Accented characters are folded to their non-accented upper case form.
-i Ignore characters outside the ASCII range 040-0176 in non-numeric comparisons.
-w Like -i, but ignore only tabs and spaces.
-n An initial numeric string, consisting of optional white space, optional plus or minus sign, and zero or more digits with optional
decimal point, is sorted by arithmetic value.
-g Numbers, like -n but with optional e-style exponents, are sorted by value.
-r Reverse the sense of comparisons.
-tx `Tab character' separating fields is x.
The notation +pos1 -pos2 restricts a sort key to a field beginning at pos1 and ending just before pos2. Pos1 and pos2 each have the form
m.n, optionally followed by one or more of the flags Mbdfginr, where m tells a number of fields to skip from the beginning of the line and
n tells a number of characters to skip further. If any flags are present they override all the global ordering options for this key. A
missing .n means .0; a missing -pos2 means the end of the line. Under the -tx option, fields are strings separated by x; otherwise fields
are non-empty strings separated by white space. White space before a field is part of the field, except under option -b. A b flag may be
attached independently to pos1 and pos2.
The notation -k pos1[,pos2] is how POSIX sort defines fields: pos1 and pos2 have the same format but different meanings. The value of m is
origin 1 instead of origin 0 and a missing .n in pos2 is the end of the field.
When there are multiple sort keys, later keys are compared only after all earlier keys compare equal. Lines that otherwise compare equal
are ordered with all bytes significant.
These option arguments are also understood:
-c Check that the single input file is sorted according to the ordering rules; give no output unless the file is out of sort.
-m Merge; assume the input files are already sorted.
-u Suppress all but one in each set of equal lines. Ignored bytes and bytes outside keys do not participate in this comparison.
-o The next argument is the name of an output file to use instead of the standard output. This file may be the same as one of the
inputs.
-Tdir Put temporary files in dir rather than in /var/tmp.
EXAMPLES
Print in alphabetical order all the unique spellings
in a list of words where capitalized words differ from uncapitalized.
Print the users file
sorted by user name (the second colon-separated field).
Print the first instance of each month in an already sorted file.
Options -um with just one input file make the choice of a unique representative from a set of equal lines predictable.
grep -n '^' input | sort -t: +1f +0n | sed 's/[0-9]*://'
A stable sort: input lines that compare equal will come out in their original order.
FILES
/var/tmp/sort.<pid>.<ordinal>
SOURCE
/src/cmd/sort.c
SEE ALSO uniq(1), look(1)DIAGNOSTICS
Sort comments and exits with non-null status for various trouble conditions and for disorder discovered under option -c.
BUGS
An external null character can be confused with an internally generated end-of-field character. The result can make a sub-field not sort
less than a longer field.
Some of the options, e.g. -i and -M, are hopelessly provincial.
SORT(1)