How the AWK works when 2 files are interchanged in a script while comparing
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
-2
down vote
favorite
In the below awk
script, when the file names are interchanged I could see 2 different result. I'm curious to know here how awk writes output to the console with different result in each case
File 1:
abc bca cdb
abc few bre
bbc bba cdb
cbc frw bte
File 2:
abc bca cdb
gbc fiw bpe
bbc bca cdb
cbc frw bte
Script :
awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file1 file2**
Output :
gbc fiw bpe
bbc bca cdb
Script:
awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file2 file1**
Output:
abc few bre
bbc bba cdb
awk
add a comment |Â
up vote
-2
down vote
favorite
In the below awk
script, when the file names are interchanged I could see 2 different result. I'm curious to know here how awk writes output to the console with different result in each case
File 1:
abc bca cdb
abc few bre
bbc bba cdb
cbc frw bte
File 2:
abc bca cdb
gbc fiw bpe
bbc bca cdb
cbc frw bte
Script :
awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file1 file2**
Output :
gbc fiw bpe
bbc bca cdb
Script:
awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file2 file1**
Output:
abc few bre
bbc bba cdb
awk
add a comment |Â
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
In the below awk
script, when the file names are interchanged I could see 2 different result. I'm curious to know here how awk writes output to the console with different result in each case
File 1:
abc bca cdb
abc few bre
bbc bba cdb
cbc frw bte
File 2:
abc bca cdb
gbc fiw bpe
bbc bca cdb
cbc frw bte
Script :
awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file1 file2**
Output :
gbc fiw bpe
bbc bca cdb
Script:
awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file2 file1**
Output:
abc few bre
bbc bba cdb
awk
In the below awk
script, when the file names are interchanged I could see 2 different result. I'm curious to know here how awk writes output to the console with different result in each case
File 1:
abc bca cdb
abc few bre
bbc bba cdb
cbc frw bte
File 2:
abc bca cdb
gbc fiw bpe
bbc bca cdb
cbc frw bte
Script :
awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file1 file2**
Output :
gbc fiw bpe
bbc bca cdb
Script:
awk 'FNR==NR a[$1$2$3]++;next;!(($1$2$3) in a)' **file2 file1**
Output:
abc few bre
bbc bba cdb
awk
edited Jul 18 at 14:26
Jesse_b
10.1k22658
10.1k22658
asked Jul 18 at 13:14
Varun Gowda
33
33
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
The first command gives you the lines in file2
that can't be found in file1
while the second command gives you the lines in file1
that can't be found in file2
.
For the given data, the code is equivalent to
awk 'FNR==NR a[$0]++; next !($0 in a)'
where a
is an array that has been keyed with the lines from the first file. The condition at the end says "print this line (from the second file) if it's not found in the first file".
Thanks for the info...
â Varun Gowda
Jul 18 at 17:42
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
The first command gives you the lines in file2
that can't be found in file1
while the second command gives you the lines in file1
that can't be found in file2
.
For the given data, the code is equivalent to
awk 'FNR==NR a[$0]++; next !($0 in a)'
where a
is an array that has been keyed with the lines from the first file. The condition at the end says "print this line (from the second file) if it's not found in the first file".
Thanks for the info...
â Varun Gowda
Jul 18 at 17:42
add a comment |Â
up vote
0
down vote
accepted
The first command gives you the lines in file2
that can't be found in file1
while the second command gives you the lines in file1
that can't be found in file2
.
For the given data, the code is equivalent to
awk 'FNR==NR a[$0]++; next !($0 in a)'
where a
is an array that has been keyed with the lines from the first file. The condition at the end says "print this line (from the second file) if it's not found in the first file".
Thanks for the info...
â Varun Gowda
Jul 18 at 17:42
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
The first command gives you the lines in file2
that can't be found in file1
while the second command gives you the lines in file1
that can't be found in file2
.
For the given data, the code is equivalent to
awk 'FNR==NR a[$0]++; next !($0 in a)'
where a
is an array that has been keyed with the lines from the first file. The condition at the end says "print this line (from the second file) if it's not found in the first file".
The first command gives you the lines in file2
that can't be found in file1
while the second command gives you the lines in file1
that can't be found in file2
.
For the given data, the code is equivalent to
awk 'FNR==NR a[$0]++; next !($0 in a)'
where a
is an array that has been keyed with the lines from the first file. The condition at the end says "print this line (from the second file) if it's not found in the first file".
answered Jul 18 at 15:02
Kusalananda
101k13199312
101k13199312
Thanks for the info...
â Varun Gowda
Jul 18 at 17:42
add a comment |Â
Thanks for the info...
â Varun Gowda
Jul 18 at 17:42
Thanks for the info...
â Varun Gowda
Jul 18 at 17:42
Thanks for the info...
â Varun Gowda
Jul 18 at 17:42
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f456990%2fhow-the-awk-works-when-2-files-are-interchanged-in-a-script-while-comparing%23new-answer', 'question_page');
);
Post as a guest
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
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
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