How to compare two different files line by line in unix? Announcing the arrival of Valued...
Is it a good idea to use CNN to classify 1D signal?
Can a party unilaterally change candidates in preparation for a General election?
What's the meaning of "fortified infraction restraint"?
Is the Standard Deduction better than Itemized when both are the same amount?
How come Sam didn't become Lord of Horn Hill?
Can you use the Shield Master feat to shove someone before you make an attack by using a Readied action?
How could we fake a moon landing now?
How do I find out the mythology and history of my Fortress?
When the Haste spell ends on a creature, do attackers have advantage against that creature?
How to convince students of the implication truth values?
What do you call the main part of a joke?
Trademark violation for app?
How to tell that you are a giant?
Wu formula for manifolds with boundary
Uniqueness of spanning tree on a grid.
Do jazz musicians improvise on the parent scale in addition to the chord-scales?
What are the out-of-universe reasons for the references to Toby Maguire-era Spider-Man in ITSV
2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?
Can melee weapons be used to deliver Contact Poisons?
When was Kai Tak permanently closed to cargo service?
Around usage results
8 Prisoners wearing hats
What do you call a floor made of glass so you can see through the floor?
Do I really need to have a message in a novel to appeal to readers?
How to compare two different files line by line in unix?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionUsing 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
add a comment |
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
5
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
16 hours ago
3
You might want to take a look atdiff
.
– Panki
16 hours ago
1
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
14 hours ago
1
@GiacomoAlzetta The thing withcomm
is that it requires sorted input. Apart from the fact that the example in the question does have sorted input, the question never asserts that this is the actual data that is being used and never says anything about the ordering of the data.
– Kusalananda♦
12 hours ago
2
αғsнιη'snl
trick is useful withcomm
for imposing sorted-ness on the files.
– glenn jackman
8 hours ago
add a comment |
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 15 hours ago
αғsнιη
17.4k103070
17.4k103070
New contributor
asked 16 hours ago
VeluVelu
361
361
New contributor
New contributor
5
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
16 hours ago
3
You might want to take a look atdiff
.
– Panki
16 hours ago
1
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
14 hours ago
1
@GiacomoAlzetta The thing withcomm
is that it requires sorted input. Apart from the fact that the example in the question does have sorted input, the question never asserts that this is the actual data that is being used and never says anything about the ordering of the data.
– Kusalananda♦
12 hours ago
2
αғsнιη'snl
trick is useful withcomm
for imposing sorted-ness on the files.
– glenn jackman
8 hours ago
add a comment |
5
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
16 hours ago
3
You might want to take a look atdiff
.
– Panki
16 hours ago
1
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
14 hours ago
1
@GiacomoAlzetta The thing withcomm
is that it requires sorted input. Apart from the fact that the example in the question does have sorted input, the question never asserts that this is the actual data that is being used and never says anything about the ordering of the data.
– Kusalananda♦
12 hours ago
2
αғsнιη'snl
trick is useful withcomm
for imposing sorted-ness on the files.
– glenn jackman
8 hours ago
5
5
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
16 hours ago
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
16 hours ago
3
3
You might want to take a look at
diff
.– Panki
16 hours ago
You might want to take a look at
diff
.– Panki
16 hours ago
1
1
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
14 hours ago
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
14 hours ago
1
1
@GiacomoAlzetta The thing with
comm
is that it requires sorted input. Apart from the fact that the example in the question does have sorted input, the question never asserts that this is the actual data that is being used and never says anything about the ordering of the data.– Kusalananda♦
12 hours ago
@GiacomoAlzetta The thing with
comm
is that it requires sorted input. Apart from the fact that the example in the question does have sorted input, the question never asserts that this is the actual data that is being used and never says anything about the ordering of the data.– Kusalananda♦
12 hours ago
2
2
αғsнιη's
nl
trick is useful with comm
for imposing sorted-ness on the files.– glenn jackman
8 hours ago
αғsнιη's
nl
trick is useful with comm
for imposing sorted-ness on the files.– glenn jackman
8 hours ago
add a comment |
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' '$1 == $2 { print "TRUE"; next } { print "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
.
Nice use of paste. You could writeawk -F't' '{print ($1 == $2) ? "TRUE" : "FALSE"}'
– glenn jackman
3 hours ago
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')
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
4
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♦
15 hours ago
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 14 hours ago
Mathieu
1,95711519
1,95711519
answered 15 hours ago
αғsнιηαғsнιη
17.4k103070
17.4k103070
add a comment |
add a comment |
Assuming the files contain no tab-characters:
$ paste file1 file2 | awk -F 't' '$1 == $2 { print "TRUE"; next } { print "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
.
Nice use of paste. You could writeawk -F't' '{print ($1 == $2) ? "TRUE" : "FALSE"}'
– glenn jackman
3 hours ago
add a comment |
Assuming the files contain no tab-characters:
$ paste file1 file2 | awk -F 't' '$1 == $2 { print "TRUE"; next } { print "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
.
Nice use of paste. You could writeawk -F't' '{print ($1 == $2) ? "TRUE" : "FALSE"}'
– glenn jackman
3 hours ago
add a comment |
Assuming the files contain no tab-characters:
$ paste file1 file2 | awk -F 't' '$1 == $2 { print "TRUE"; next } { print "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' '$1 == $2 { print "TRUE"; next } { print "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 15 hours ago
answered 15 hours ago
Kusalananda♦Kusalananda
142k18266442
142k18266442
Nice use of paste. You could writeawk -F't' '{print ($1 == $2) ? "TRUE" : "FALSE"}'
– glenn jackman
3 hours ago
add a comment |
Nice use of paste. You could writeawk -F't' '{print ($1 == $2) ? "TRUE" : "FALSE"}'
– glenn jackman
3 hours ago
Nice use of paste. You could write
awk -F't' '{print ($1 == $2) ? "TRUE" : "FALSE"}'
– glenn jackman
3 hours ago
Nice use of paste. You could write
awk -F't' '{print ($1 == $2) ? "TRUE" : "FALSE"}'
– glenn jackman
3 hours ago
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 14 hours ago
answered 14 hours ago
Stéphane ChazelasStéphane Chazelas
315k57597955
315k57597955
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')
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')
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 9 hours ago
wjandreawjandrea
524414
524414
add a comment |
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 7 hours ago
Kusalananda♦
142k18266442
142k18266442
answered 8 hours ago
glenn jackmanglenn jackman
53.1k573114
53.1k573114
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
4
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♦
15 hours ago
add a comment |
Try this,
awk 'FNR==NR {a[$0]; next} {if ($0 in a){print "TRUE"} else {print "FALSE"}}' File2 File1
4
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♦
15 hours ago
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 15 hours ago
msp9011msp9011
4,70844167
4,70844167
4
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♦
15 hours ago
add a comment |
4
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♦
15 hours ago
4
4
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♦
15 hours ago
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♦
15 hours ago
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
5
What happens if the two files are of unequal length? What part of the solution of this issue are you having problems with?
– Kusalananda♦
16 hours ago
3
You might want to take a look at
diff
.– Panki
16 hours ago
1
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
14 hours ago
1
@GiacomoAlzetta The thing with
comm
is that it requires sorted input. Apart from the fact that the example in the question does have sorted input, the question never asserts that this is the actual data that is being used and never says anything about the ordering of the data.– Kusalananda♦
12 hours ago
2
αғsнιη's
nl
trick is useful withcomm
for imposing sorted-ness on the files.– glenn jackman
8 hours ago