How to compare two different files line by line in unix? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionCompare two files and return a true or false valueUsing diff to compare the output of two commandsMerging two Unix filesCompare two files with four columnsCompare two files and matched line send to new filecompare two files and print matches - large filesScript comparing two files, match two strings anywhere on lineCompare two a columns in two csv files and print to third fileCompare two files and retrieve corresponding resultsHow to compare the 1st column of two files and if the strings match then print “true”Linux Compare two files on different field and print field 1 of first fileHow to compare two CSV files and display unique records?
Why complex landing gears are used instead of simple,reliability and light weight muscle wire or shape memory alloys?
Would color changing eyes affect vision?
How to write capital alpha?
Flight departed from the gate 5 min before scheduled departure time. Refund options
Test print coming out spongy
What does it mean that physics no longer uses mechanical models to describe phenomena?
In musical terms, what properties are varied by the human voice to produce different words / syllables?
If Windows 7 doesn't support WSL, then what is "Subsystem for UNIX-based Applications"?
Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?
AppleTVs create a chatty alternate WiFi network
Asymptotics question
One-one communication
How can a team of shapeshifters communicate?
How can I save and copy a screenhot at the same time?
Is there public access to the Meteor Crater in Arizona?
A proverb that is used to imply that you have unexpectedly faced a big problem
What would you call this weird metallic apparatus that allows you to lift people?
How to change the tick of the color bar legend to black
Project Euler #1 in C++
Sally's older brother
what is the log of the PDF for a Normal Distribution?
Why not send Voyager 3 and 4 following up the paths taken by Voyager 1 and 2 to re-transmit signals of later as they fly away from Earth?
How to ternary Plot3D a function
What is the difference between a "ranged attack" and a "ranged weapon attack"?
How to compare two different files line by line in unix?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionCompare two files and return a true or false valueUsing diff to compare the output of two commandsMerging two Unix filesCompare two files with four columnsCompare two files and matched line send to new filecompare two files and print matches - large filesScript comparing two files, match two strings anywhere on lineCompare two a columns in two csv files and print to third fileCompare two files and retrieve corresponding resultsHow to compare the 1st column of two files and if the strings match then print “true”Linux Compare two files on different field and print field 1 of first fileHow to compare two CSV files and display unique records?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
File1:
123
234
345
456
File2:
123
234
343
758
Expected output:
File3:
TRUE
TRUE
FALSE
FALSE
so the code should compare two files and print 'TRUE' if it matches otherwise it should print 'FALSE' in the new file. Could anyone please provide the solution for this?
text-processing awk diff
New contributor
|
show 2 more comments
File1:
123
234
345
456
File2:
123
234
343
758
Expected output:
File3:
TRUE
TRUE
FALSE
FALSE
so the code should compare two files and print 'TRUE' if it matches otherwise it should print 'FALSE' in the new file. Could anyone please provide the solution for this?
text-processing awk diff
New contributor
10
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
Apr 17 at 9:33
9
You might want to take a look atdiff
.
– Panki
Apr 17 at 9:36
2
Other useful command in these situations iscomm
. It makes it easy to list lines that both files have in common or are unique to one or the other.
– Giacomo Alzetta
Apr 17 at 12:12
2
αғsнιη'snl
trick is useful withcomm
for imposing sorted-ness on the files.
– glenn jackman
Apr 17 at 18:06
7
Possible duplicate of Compare two files and return a true or false value
– Julien Lopez
2 days ago
|
show 2 more comments
File1:
123
234
345
456
File2:
123
234
343
758
Expected output:
File3:
TRUE
TRUE
FALSE
FALSE
so the code should compare two files and print 'TRUE' if it matches otherwise it should print 'FALSE' in the new file. Could anyone please provide the solution for this?
text-processing awk diff
New contributor
File1:
123
234
345
456
File2:
123
234
343
758
Expected output:
File3:
TRUE
TRUE
FALSE
FALSE
so the code should compare two files and print 'TRUE' if it matches otherwise it should print 'FALSE' in the new file. Could anyone please provide the solution for this?
text-processing awk diff
text-processing awk diff
New contributor
New contributor
edited Apr 17 at 10:53
αғsнιη
17.7k103270
17.7k103270
New contributor
asked Apr 17 at 9:28
VeluVelu
6713
6713
New contributor
New contributor
10
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
Apr 17 at 9:33
9
You might want to take a look atdiff
.
– Panki
Apr 17 at 9:36
2
Other useful command in these situations iscomm
. It makes it easy to list lines that both files have in common or are unique to one or the other.
– Giacomo Alzetta
Apr 17 at 12:12
2
αғsнιη'snl
trick is useful withcomm
for imposing sorted-ness on the files.
– glenn jackman
Apr 17 at 18:06
7
Possible duplicate of Compare two files and return a true or false value
– Julien Lopez
2 days ago
|
show 2 more comments
10
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
Apr 17 at 9:33
9
You might want to take a look atdiff
.
– Panki
Apr 17 at 9:36
2
Other useful command in these situations iscomm
. It makes it easy to list lines that both files have in common or are unique to one or the other.
– Giacomo Alzetta
Apr 17 at 12:12
2
αғsнιη'snl
trick is useful withcomm
for imposing sorted-ness on the files.
– glenn jackman
Apr 17 at 18:06
7
Possible duplicate of Compare two files and return a true or false value
– Julien Lopez
2 days ago
10
10
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
Apr 17 at 9:33
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
Apr 17 at 9:33
9
9
You might want to take a look at
diff
.– Panki
Apr 17 at 9:36
You might want to take a look at
diff
.– Panki
Apr 17 at 9:36
2
2
Other useful command in these situations is
comm
. It makes it easy to list lines that both files have in common or are unique to one or the other.– Giacomo Alzetta
Apr 17 at 12:12
Other useful command in these situations is
comm
. It makes it easy to list lines that both files have in common or are unique to one or the other.– Giacomo Alzetta
Apr 17 at 12:12
2
2
αғsнιη's
nl
trick is useful with comm
for imposing sorted-ness on the files.– glenn jackman
Apr 17 at 18:06
αғsнιη's
nl
trick is useful with comm
for imposing sorted-ness on the files.– glenn jackman
Apr 17 at 18:06
7
7
Possible duplicate of Compare two files and return a true or false value
– Julien Lopez
2 days ago
Possible duplicate of Compare two files and return a true or false value
– Julien Lopez
2 days ago
|
show 2 more comments
6 Answers
6
active
oldest
votes
Use diff
command as following, in bash
or any other shell that supports <(...)
process substitutions or you can emulate it as shown here:
diff --new-line-format='FALSE'$'n'
--old-line-format=''
--unchanged-line-format='TRUE'$'n'
<(nl file1) <(nl file2)
Output would be:
TRUE
TRUE
FALSE
FALSE
--new-line-format='FALSE'$'n
, print FALSE
if lines were differ and with --old-line-format=''
we disable output if line was differ for file1 which is known as old file to diff command (We could swap these as well, meaning that one of them should print FALSE
another should be disabled.)
--unchanged-line-format='TRUE'$'n'
, print TRUE
if lines were same. the $'n'
C-style escaping syntax is used to printing a new line after each line output.
add a comment |
Assuming the files contain no tab-characters:
$ paste file1 file2 | awk -F 't' ' print ($1 == $2 ? "TRUE" : "FALSE") '
TRUE
TRUE
FALSE
FALSE
This uses paste
to create two tab-delimited columns, with the contents of the two files in either column. The awk
command compares the two columns on each line and prints TRUE
if the columns are the same and otherwise prints FALSE
.
add a comment |
Assuming both files have the same number of lines:
awk 'getline f2 < "file2"; print f2 == $0 ? "TRUE" : "FALSE"' file1
That's doing a numerical comparison if the strings to compare are numbers and lexical otherwise. For instance, 100
and 1.0e2
would be considered identical. Change to f2"" == $0
to force a lexical comparison in any case.
Depending on the awk
implementation, lexical comparison will be done as if by using memcmp()
(byte-to-byte comparison) or as if by using strcoll()
(whether the two strings sort the same in the locale's collation order). That can make a difference in some locales where the order is not properly defined for some characters, not on all decimal digit input like in your sample.
add a comment |
Python 3
with open('file1') as file1, open('file2') as file2:
for line1, line2 in zip(file1, file2):
print(line1 == line2)
Output:
True
True
False
False
If you need TRUE
and FALSE
in uppercase, replace the print line with one of these:
print(str(line1 == line2).upper())
print('TRUE' if line1 == line2 else 'FALSE')
2
In Python 2, do animport itertools
first, and then useitertools.izip
instead ofzip
. Otherwise it will read both files to memory, possibly using too much memory.
– pts
yesterday
add a comment |
In bash
, reading from each file in a while
loop, comparing the read lines and printing TRUE
or FALSE
appropriately:
while IFS= read -r -u3 line1; IFS= read -r -u4 line2; do
[[ $line1 == $line2 ]] && echo TRUE || echo FALSE
done 3<file1 4<file2
The two calls to read
reads from file descriptor 3 and 4 respectively. The files are redirected to these with two input redirections into the loop.
add a comment |
Try this,
awk 'FNR==NR a[$0]; next if ($0 in a)print "TRUE" else print "FALSE"' File2 File1
5
This seems to be checking whether the first file contains each line of the second file and printTRUE
if it does andFALSE
if it doesn't (for each line), regardless of where in the first file the line is located. It does not compare lines line by line.
– Kusalananda♦
Apr 17 at 10:33
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Velu is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f512953%2fhow-to-compare-two-different-files-line-by-line-in-unix%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use diff
command as following, in bash
or any other shell that supports <(...)
process substitutions or you can emulate it as shown here:
diff --new-line-format='FALSE'$'n'
--old-line-format=''
--unchanged-line-format='TRUE'$'n'
<(nl file1) <(nl file2)
Output would be:
TRUE
TRUE
FALSE
FALSE
--new-line-format='FALSE'$'n
, print FALSE
if lines were differ and with --old-line-format=''
we disable output if line was differ for file1 which is known as old file to diff command (We could swap these as well, meaning that one of them should print FALSE
another should be disabled.)
--unchanged-line-format='TRUE'$'n'
, print TRUE
if lines were same. the $'n'
C-style escaping syntax is used to printing a new line after each line output.
add a comment |
Use diff
command as following, in bash
or any other shell that supports <(...)
process substitutions or you can emulate it as shown here:
diff --new-line-format='FALSE'$'n'
--old-line-format=''
--unchanged-line-format='TRUE'$'n'
<(nl file1) <(nl file2)
Output would be:
TRUE
TRUE
FALSE
FALSE
--new-line-format='FALSE'$'n
, print FALSE
if lines were differ and with --old-line-format=''
we disable output if line was differ for file1 which is known as old file to diff command (We could swap these as well, meaning that one of them should print FALSE
another should be disabled.)
--unchanged-line-format='TRUE'$'n'
, print TRUE
if lines were same. the $'n'
C-style escaping syntax is used to printing a new line after each line output.
add a comment |
Use diff
command as following, in bash
or any other shell that supports <(...)
process substitutions or you can emulate it as shown here:
diff --new-line-format='FALSE'$'n'
--old-line-format=''
--unchanged-line-format='TRUE'$'n'
<(nl file1) <(nl file2)
Output would be:
TRUE
TRUE
FALSE
FALSE
--new-line-format='FALSE'$'n
, print FALSE
if lines were differ and with --old-line-format=''
we disable output if line was differ for file1 which is known as old file to diff command (We could swap these as well, meaning that one of them should print FALSE
another should be disabled.)
--unchanged-line-format='TRUE'$'n'
, print TRUE
if lines were same. the $'n'
C-style escaping syntax is used to printing a new line after each line output.
Use diff
command as following, in bash
or any other shell that supports <(...)
process substitutions or you can emulate it as shown here:
diff --new-line-format='FALSE'$'n'
--old-line-format=''
--unchanged-line-format='TRUE'$'n'
<(nl file1) <(nl file2)
Output would be:
TRUE
TRUE
FALSE
FALSE
--new-line-format='FALSE'$'n
, print FALSE
if lines were differ and with --old-line-format=''
we disable output if line was differ for file1 which is known as old file to diff command (We could swap these as well, meaning that one of them should print FALSE
another should be disabled.)
--unchanged-line-format='TRUE'$'n'
, print TRUE
if lines were same. the $'n'
C-style escaping syntax is used to printing a new line after each line output.
edited Apr 17 at 12:09
Mathieu
1,96711520
1,96711520
answered Apr 17 at 10:35
αғsнιηαғsнιη
17.7k103270
17.7k103270
add a comment |
add a comment |
Assuming the files contain no tab-characters:
$ paste file1 file2 | awk -F 't' ' print ($1 == $2 ? "TRUE" : "FALSE") '
TRUE
TRUE
FALSE
FALSE
This uses paste
to create two tab-delimited columns, with the contents of the two files in either column. The awk
command compares the two columns on each line and prints TRUE
if the columns are the same and otherwise prints FALSE
.
add a comment |
Assuming the files contain no tab-characters:
$ paste file1 file2 | awk -F 't' ' print ($1 == $2 ? "TRUE" : "FALSE") '
TRUE
TRUE
FALSE
FALSE
This uses paste
to create two tab-delimited columns, with the contents of the two files in either column. The awk
command compares the two columns on each line and prints TRUE
if the columns are the same and otherwise prints FALSE
.
add a comment |
Assuming the files contain no tab-characters:
$ paste file1 file2 | awk -F 't' ' print ($1 == $2 ? "TRUE" : "FALSE") '
TRUE
TRUE
FALSE
FALSE
This uses paste
to create two tab-delimited columns, with the contents of the two files in either column. The awk
command compares the two columns on each line and prints TRUE
if the columns are the same and otherwise prints FALSE
.
Assuming the files contain no tab-characters:
$ paste file1 file2 | awk -F 't' ' print ($1 == $2 ? "TRUE" : "FALSE") '
TRUE
TRUE
FALSE
FALSE
This uses paste
to create two tab-delimited columns, with the contents of the two files in either column. The awk
command compares the two columns on each line and prints TRUE
if the columns are the same and otherwise prints FALSE
.
edited 2 days ago
answered Apr 17 at 10:37
Kusalananda♦Kusalananda
142k18266442
142k18266442
add a comment |
add a comment |
Assuming both files have the same number of lines:
awk 'getline f2 < "file2"; print f2 == $0 ? "TRUE" : "FALSE"' file1
That's doing a numerical comparison if the strings to compare are numbers and lexical otherwise. For instance, 100
and 1.0e2
would be considered identical. Change to f2"" == $0
to force a lexical comparison in any case.
Depending on the awk
implementation, lexical comparison will be done as if by using memcmp()
(byte-to-byte comparison) or as if by using strcoll()
(whether the two strings sort the same in the locale's collation order). That can make a difference in some locales where the order is not properly defined for some characters, not on all decimal digit input like in your sample.
add a comment |
Assuming both files have the same number of lines:
awk 'getline f2 < "file2"; print f2 == $0 ? "TRUE" : "FALSE"' file1
That's doing a numerical comparison if the strings to compare are numbers and lexical otherwise. For instance, 100
and 1.0e2
would be considered identical. Change to f2"" == $0
to force a lexical comparison in any case.
Depending on the awk
implementation, lexical comparison will be done as if by using memcmp()
(byte-to-byte comparison) or as if by using strcoll()
(whether the two strings sort the same in the locale's collation order). That can make a difference in some locales where the order is not properly defined for some characters, not on all decimal digit input like in your sample.
add a comment |
Assuming both files have the same number of lines:
awk 'getline f2 < "file2"; print f2 == $0 ? "TRUE" : "FALSE"' file1
That's doing a numerical comparison if the strings to compare are numbers and lexical otherwise. For instance, 100
and 1.0e2
would be considered identical. Change to f2"" == $0
to force a lexical comparison in any case.
Depending on the awk
implementation, lexical comparison will be done as if by using memcmp()
(byte-to-byte comparison) or as if by using strcoll()
(whether the two strings sort the same in the locale's collation order). That can make a difference in some locales where the order is not properly defined for some characters, not on all decimal digit input like in your sample.
Assuming both files have the same number of lines:
awk 'getline f2 < "file2"; print f2 == $0 ? "TRUE" : "FALSE"' file1
That's doing a numerical comparison if the strings to compare are numbers and lexical otherwise. For instance, 100
and 1.0e2
would be considered identical. Change to f2"" == $0
to force a lexical comparison in any case.
Depending on the awk
implementation, lexical comparison will be done as if by using memcmp()
(byte-to-byte comparison) or as if by using strcoll()
(whether the two strings sort the same in the locale's collation order). That can make a difference in some locales where the order is not properly defined for some characters, not on all decimal digit input like in your sample.
edited Apr 17 at 12:04
answered Apr 17 at 11:33
Stéphane ChazelasStéphane Chazelas
315k57598956
315k57598956
add a comment |
add a comment |
Python 3
with open('file1') as file1, open('file2') as file2:
for line1, line2 in zip(file1, file2):
print(line1 == line2)
Output:
True
True
False
False
If you need TRUE
and FALSE
in uppercase, replace the print line with one of these:
print(str(line1 == line2).upper())
print('TRUE' if line1 == line2 else 'FALSE')
2
In Python 2, do animport itertools
first, and then useitertools.izip
instead ofzip
. Otherwise it will read both files to memory, possibly using too much memory.
– pts
yesterday
add a comment |
Python 3
with open('file1') as file1, open('file2') as file2:
for line1, line2 in zip(file1, file2):
print(line1 == line2)
Output:
True
True
False
False
If you need TRUE
and FALSE
in uppercase, replace the print line with one of these:
print(str(line1 == line2).upper())
print('TRUE' if line1 == line2 else 'FALSE')
2
In Python 2, do animport itertools
first, and then useitertools.izip
instead ofzip
. Otherwise it will read both files to memory, possibly using too much memory.
– pts
yesterday
add a comment |
Python 3
with open('file1') as file1, open('file2') as file2:
for line1, line2 in zip(file1, file2):
print(line1 == line2)
Output:
True
True
False
False
If you need TRUE
and FALSE
in uppercase, replace the print line with one of these:
print(str(line1 == line2).upper())
print('TRUE' if line1 == line2 else 'FALSE')
Python 3
with open('file1') as file1, open('file2') as file2:
for line1, line2 in zip(file1, file2):
print(line1 == line2)
Output:
True
True
False
False
If you need TRUE
and FALSE
in uppercase, replace the print line with one of these:
print(str(line1 == line2).upper())
print('TRUE' if line1 == line2 else 'FALSE')
answered Apr 17 at 17:17
wjandreawjandrea
584414
584414
2
In Python 2, do animport itertools
first, and then useitertools.izip
instead ofzip
. Otherwise it will read both files to memory, possibly using too much memory.
– pts
yesterday
add a comment |
2
In Python 2, do animport itertools
first, and then useitertools.izip
instead ofzip
. Otherwise it will read both files to memory, possibly using too much memory.
– pts
yesterday
2
2
In Python 2, do an
import itertools
first, and then use itertools.izip
instead of zip
. Otherwise it will read both files to memory, possibly using too much memory.– pts
yesterday
In Python 2, do an
import itertools
first, and then use itertools.izip
instead of zip
. Otherwise it will read both files to memory, possibly using too much memory.– pts
yesterday
add a comment |
In bash
, reading from each file in a while
loop, comparing the read lines and printing TRUE
or FALSE
appropriately:
while IFS= read -r -u3 line1; IFS= read -r -u4 line2; do
[[ $line1 == $line2 ]] && echo TRUE || echo FALSE
done 3<file1 4<file2
The two calls to read
reads from file descriptor 3 and 4 respectively. The files are redirected to these with two input redirections into the loop.
add a comment |
In bash
, reading from each file in a while
loop, comparing the read lines and printing TRUE
or FALSE
appropriately:
while IFS= read -r -u3 line1; IFS= read -r -u4 line2; do
[[ $line1 == $line2 ]] && echo TRUE || echo FALSE
done 3<file1 4<file2
The two calls to read
reads from file descriptor 3 and 4 respectively. The files are redirected to these with two input redirections into the loop.
add a comment |
In bash
, reading from each file in a while
loop, comparing the read lines and printing TRUE
or FALSE
appropriately:
while IFS= read -r -u3 line1; IFS= read -r -u4 line2; do
[[ $line1 == $line2 ]] && echo TRUE || echo FALSE
done 3<file1 4<file2
The two calls to read
reads from file descriptor 3 and 4 respectively. The files are redirected to these with two input redirections into the loop.
In bash
, reading from each file in a while
loop, comparing the read lines and printing TRUE
or FALSE
appropriately:
while IFS= read -r -u3 line1; IFS= read -r -u4 line2; do
[[ $line1 == $line2 ]] && echo TRUE || echo FALSE
done 3<file1 4<file2
The two calls to read
reads from file descriptor 3 and 4 respectively. The files are redirected to these with two input redirections into the loop.
edited Apr 17 at 19:12
Kusalananda♦
142k18266442
142k18266442
answered Apr 17 at 18:04
glenn jackmanglenn jackman
53.2k573114
53.2k573114
add a comment |
add a comment |
Try this,
awk 'FNR==NR a[$0]; next if ($0 in a)print "TRUE" else print "FALSE"' File2 File1
5
This seems to be checking whether the first file contains each line of the second file and printTRUE
if it does andFALSE
if it doesn't (for each line), regardless of where in the first file the line is located. It does not compare lines line by line.
– Kusalananda♦
Apr 17 at 10:33
add a comment |
Try this,
awk 'FNR==NR a[$0]; next if ($0 in a)print "TRUE" else print "FALSE"' File2 File1
5
This seems to be checking whether the first file contains each line of the second file and printTRUE
if it does andFALSE
if it doesn't (for each line), regardless of where in the first file the line is located. It does not compare lines line by line.
– Kusalananda♦
Apr 17 at 10:33
add a comment |
Try this,
awk 'FNR==NR a[$0]; next if ($0 in a)print "TRUE" else print "FALSE"' File2 File1
Try this,
awk 'FNR==NR a[$0]; next if ($0 in a)print "TRUE" else print "FALSE"' File2 File1
answered Apr 17 at 10:25
msp9011msp9011
4,70844167
4,70844167
5
This seems to be checking whether the first file contains each line of the second file and printTRUE
if it does andFALSE
if it doesn't (for each line), regardless of where in the first file the line is located. It does not compare lines line by line.
– Kusalananda♦
Apr 17 at 10:33
add a comment |
5
This seems to be checking whether the first file contains each line of the second file and printTRUE
if it does andFALSE
if it doesn't (for each line), regardless of where in the first file the line is located. It does not compare lines line by line.
– Kusalananda♦
Apr 17 at 10:33
5
5
This seems to be checking whether the first file contains each line of the second file and print
TRUE
if it does and FALSE
if it doesn't (for each line), regardless of where in the first file the line is located. It does not compare lines line by line.– Kusalananda♦
Apr 17 at 10:33
This seems to be checking whether the first file contains each line of the second file and print
TRUE
if it does and FALSE
if it doesn't (for each line), regardless of where in the first file the line is located. It does not compare lines line by line.– Kusalananda♦
Apr 17 at 10:33
add a comment |
Velu is a new contributor. Be nice, and check out our Code of Conduct.
Velu is a new contributor. Be nice, and check out our Code of Conduct.
Velu is a new contributor. Be nice, and check out our Code of Conduct.
Velu is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f512953%2fhow-to-compare-two-different-files-line-by-line-in-unix%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
10
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
Apr 17 at 9:33
9
You might want to take a look at
diff
.– Panki
Apr 17 at 9:36
2
Other useful command in these situations is
comm
. It makes it easy to list lines that both files have in common or are unique to one or the other.– Giacomo Alzetta
Apr 17 at 12:12
2
αғsнιη's
nl
trick is useful withcomm
for imposing sorted-ness on the files.– glenn jackman
Apr 17 at 18:06
7
Possible duplicate of Compare two files and return a true or false value
– Julien Lopez
2 days ago