Comparing two one-line files and selecting what does not match
I have two files. One is consisting of one line, with data separated by spaces and each number appearing only once.
The other is consisting of one column and multiple lines which can have some numbers appearing more than once.
It looks something like this:
file 1:
file2:
(The files are a result of some other processing and scripts so there could be some extra spaces or tabs that I cannot easily influence/remove)
I would like to print the lines from file2 that do not have a match in file1. It is very important that in case there aren't any lines in file2 that do not have a match in file1 (i.e. when the file2 doesn't contain any numbers that aren't already in file1), I get a completely empty file, and not spaces or any other characters.
I have found some ways to do it when both files are columns, but not when one of them is a one line. When I tried transforming the one line file into a one column file, I got some unwanted spaces in the output.
Thank you!
Moderator's Comments:
Please use CODE tags as required by forum rules!
Last edited by RudiC; 08-15-2018 at 07:17 PM..
Reason: Added CODE tags.
Hello all,
I always found help for my problems using the search option, but this time my request is too specific. I have two files that I want to compare. File1 is the index and File2 contains the data:
File1:
chr1 protein_coding exon 500 600 . + . gene_id "20532";... (0 Replies)
Hi guys,
I'm rather new at using UNIX based systems, and when it comes to scripting etc I'm even newer.
I have two files which i need to compare.
file1: (some random ID's)
451245
451288
136588
784522
file2: (random ID's + e-mail assigned to ID)
123888 xc@xc.com
451245 ... (21 Replies)
I have two text files where the first three columns are exactly the same. I want to compare the fourth column of the text files and if the values are different, print that row into a new output file. How do I go about doing that?
File 1:
100 rs3794811 0.01 0.3434
100 rs8066551 0.01... (8 Replies)
Hi,
I have two text files with matching first columns. Some of the values in the second column do not match. I want to write a script to print out the rows (only the first column) where the values in the second column do not match.
Example:
Input 1
A 1
B 2
C 3
D 4
Input 2
A 2
B 2... (6 Replies)
Hi All,
I want to compare two files using shell script. One file will be input file and each line of input file will be compared against the other file.
for e.g.
File 1
10.3.242.170 saquatch Tesr.adc.unix.com jndi_p1 jndi_p1.unix.com
10.3.242.171 ness... (10 Replies)
I'm looking to match an error code against a list of possible codes and get the nearest match. The code would be a 6 character hexadecimal string.
I have a file of error codes all of which have a specific first 3 characters, however, after that the last 3 characters may be specific or generic as... (3 Replies)
Hi,
I have been trying to find help with my issue and I'm thinking awk may be able to do it.
I have two files eg
file1.txt
STRING1 230 400 0.36
STRING2 400 230 -0.13
STRING3 130 349 1
file2.txt
CUFFFLINKS 1 1394 93932 . + STRING1
CUFFFLINKS ... (9 Replies)
Hello all, First post here. I did not notice a previous post to help me down the right path. I am looking to compare a column in a CSV file against another file (which is not a column match one for one) but more or less when a match is made, I would like to append a third column that contains a... (17 Replies)
I have two file as given below which shows the ACL permissions of each file. I need to compare the source file with target file and list down the difference as specified below in required output. Can someone help me on this ?
Source File
*************
# file: /local/test_1
# owner: own
#... (4 Replies)
I have a file with contents as shown in file.texi
Would like to keep only the sections that have inlineifset till the empty line is reached. Finally replace the
following string with a space
@inlineifset{mrg, @opar{@bullet{}
I had written the following command but it messed my file
... (6 Replies)
Discussion started by: Danette
6 Replies
LEARN ABOUT PLAN9
diff
DIFF(1) General Commands Manual DIFF(1)NAME
diff - differential file comparator
SYNOPSIS
diff [ -efbwr ] file1 ... file2
DESCRIPTION
Diff tells what lines must be changed in two files to bring them into agreement. If one file is a directory, then a file in that directory
with basename the same as that of the other file is used. If both files are directories, similarly named files in the two directories are
compared by the method of diff for text files and cmp(1) otherwise. If more than two file names are given, then each argument is compared
to the last argument as above. The -r option causes diff to process similarly named subdirectories recursively. The normal output con-
tains lines of these forms:
n1 a n3,n4
n1,n2 d n3
n1,n2 c n3,n4
These lines resemble ed commands to convert file1 into file2. The numbers after the letters pertain to file2. In fact, by exchanging `a'
for `d' and reading backward one may ascertain equally how to convert file2 into file1. As in ed, identical pairs where n1 = n2 or n3 = n4
are abbreviated as a single number.
Following each of these lines come all the lines that are affected in the first file flagged by `<', then all the lines that are affected
in the second file flagged by `>'.
The -b option causes trailing blanks (spaces and tabs) to be ignored and other strings of blanks to compare equal. The -w option causes
all white-space to be removed from input lines before applying the difference algorithm.
The -e option produces a script of a, c and d commands for the editor ed, which will recreate file2 from file1. The -f option produces a
similar script, not useful with ed, in the opposite order. It may, however, be useful as input to a stream-oriented post-processor.
Except in rare circumstances, diff finds a smallest sufficient set of file differences.
FILES
/tmp/diff[12]
SOURCE
/sys/src/cmd/diff
SEE ALSO cmp(1), ed(1)DIAGNOSTICS
Exit status is the empty string for no differences, for some, and for trouble.
BUGS
Editing scripts produced under the -e or -f option are naive about creating lines consisting of a single `.'.
When running diff on directories, the notion of what is a text file is open to debate.
DIFF(1)