Bash Script for showing difference between two text files
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
Lets say I have two lists:
guests-2016.txt
:
Peter
Michael
Frank
Dirk
guests-2017.txt
:
Mark
Michael
Dirk
Lilly
How may I create two new lists of guests
Guests that were in
guests-2016.txt
but are not inguests-2017.txt
(former_guests.txt
)Guests that were not in
guests-2016.txt
but are inguests-2017.txt
now (new_guests.txt
)
Blank lines should be ignored. Only standard utilities should be used.
My idea would be to use diff
and do some post processing.
shell-script text-processing scripting diff
add a comment |Â
up vote
4
down vote
favorite
Lets say I have two lists:
guests-2016.txt
:
Peter
Michael
Frank
Dirk
guests-2017.txt
:
Mark
Michael
Dirk
Lilly
How may I create two new lists of guests
Guests that were in
guests-2016.txt
but are not inguests-2017.txt
(former_guests.txt
)Guests that were not in
guests-2016.txt
but are inguests-2017.txt
now (new_guests.txt
)
Blank lines should be ignored. Only standard utilities should be used.
My idea would be to use diff
and do some post processing.
shell-script text-processing scripting diff
6
Check out the manual page forcomm
. Then add what you have tried, and explain how it did not work as you intended.
â DopeGhoti
Sep 26 '17 at 19:09
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Lets say I have two lists:
guests-2016.txt
:
Peter
Michael
Frank
Dirk
guests-2017.txt
:
Mark
Michael
Dirk
Lilly
How may I create two new lists of guests
Guests that were in
guests-2016.txt
but are not inguests-2017.txt
(former_guests.txt
)Guests that were not in
guests-2016.txt
but are inguests-2017.txt
now (new_guests.txt
)
Blank lines should be ignored. Only standard utilities should be used.
My idea would be to use diff
and do some post processing.
shell-script text-processing scripting diff
Lets say I have two lists:
guests-2016.txt
:
Peter
Michael
Frank
Dirk
guests-2017.txt
:
Mark
Michael
Dirk
Lilly
How may I create two new lists of guests
Guests that were in
guests-2016.txt
but are not inguests-2017.txt
(former_guests.txt
)Guests that were not in
guests-2016.txt
but are inguests-2017.txt
now (new_guests.txt
)
Blank lines should be ignored. Only standard utilities should be used.
My idea would be to use diff
and do some post processing.
shell-script text-processing scripting diff
shell-script text-processing scripting diff
edited Sep 26 '17 at 20:23
Jeff Schaller
32.3k849110
32.3k849110
asked Sep 26 '17 at 19:07
NoobieNoob
232
232
6
Check out the manual page forcomm
. Then add what you have tried, and explain how it did not work as you intended.
â DopeGhoti
Sep 26 '17 at 19:09
add a comment |Â
6
Check out the manual page forcomm
. Then add what you have tried, and explain how it did not work as you intended.
â DopeGhoti
Sep 26 '17 at 19:09
6
6
Check out the manual page for
comm
. Then add what you have tried, and explain how it did not work as you intended.â DopeGhoti
Sep 26 '17 at 19:09
Check out the manual page for
comm
. Then add what you have tried, and explain how it did not work as you intended.â DopeGhoti
Sep 26 '17 at 19:09
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
Given two sorted files, comm
would do this for you.
See the combinations of the -2 -3
and -1 -3
command line options, for example.
Thanks I did not know comm before. How to skip blank lines?
â NoobieNoob
Sep 26 '17 at 19:32
@NoobieNoob There are no blank lines in you example data, nor will there be any in the output fromcomm
.
â Kusalananda
Sep 26 '17 at 19:41
add a comment |Â
up vote
1
down vote
Check, does it do the job. I can add an explanation, if you are needed.
awk '
/^$/next
FNR == NR guest_2016[$1] = 1
FNR != NR
if(!guest_2016[$1])
print $1 > "new_guests.txt"
delete guest_2016[$1];
END
for(i in guest_2016)
print i > "former_guests.txt"
' guests-2016.txt guests-2017.txt
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Given two sorted files, comm
would do this for you.
See the combinations of the -2 -3
and -1 -3
command line options, for example.
Thanks I did not know comm before. How to skip blank lines?
â NoobieNoob
Sep 26 '17 at 19:32
@NoobieNoob There are no blank lines in you example data, nor will there be any in the output fromcomm
.
â Kusalananda
Sep 26 '17 at 19:41
add a comment |Â
up vote
3
down vote
accepted
Given two sorted files, comm
would do this for you.
See the combinations of the -2 -3
and -1 -3
command line options, for example.
Thanks I did not know comm before. How to skip blank lines?
â NoobieNoob
Sep 26 '17 at 19:32
@NoobieNoob There are no blank lines in you example data, nor will there be any in the output fromcomm
.
â Kusalananda
Sep 26 '17 at 19:41
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Given two sorted files, comm
would do this for you.
See the combinations of the -2 -3
and -1 -3
command line options, for example.
Given two sorted files, comm
would do this for you.
See the combinations of the -2 -3
and -1 -3
command line options, for example.
answered Sep 26 '17 at 19:25
Kusalananda
106k14209327
106k14209327
Thanks I did not know comm before. How to skip blank lines?
â NoobieNoob
Sep 26 '17 at 19:32
@NoobieNoob There are no blank lines in you example data, nor will there be any in the output fromcomm
.
â Kusalananda
Sep 26 '17 at 19:41
add a comment |Â
Thanks I did not know comm before. How to skip blank lines?
â NoobieNoob
Sep 26 '17 at 19:32
@NoobieNoob There are no blank lines in you example data, nor will there be any in the output fromcomm
.
â Kusalananda
Sep 26 '17 at 19:41
Thanks I did not know comm before. How to skip blank lines?
â NoobieNoob
Sep 26 '17 at 19:32
Thanks I did not know comm before. How to skip blank lines?
â NoobieNoob
Sep 26 '17 at 19:32
@NoobieNoob There are no blank lines in you example data, nor will there be any in the output from
comm
.â Kusalananda
Sep 26 '17 at 19:41
@NoobieNoob There are no blank lines in you example data, nor will there be any in the output from
comm
.â Kusalananda
Sep 26 '17 at 19:41
add a comment |Â
up vote
1
down vote
Check, does it do the job. I can add an explanation, if you are needed.
awk '
/^$/next
FNR == NR guest_2016[$1] = 1
FNR != NR
if(!guest_2016[$1])
print $1 > "new_guests.txt"
delete guest_2016[$1];
END
for(i in guest_2016)
print i > "former_guests.txt"
' guests-2016.txt guests-2017.txt
add a comment |Â
up vote
1
down vote
Check, does it do the job. I can add an explanation, if you are needed.
awk '
/^$/next
FNR == NR guest_2016[$1] = 1
FNR != NR
if(!guest_2016[$1])
print $1 > "new_guests.txt"
delete guest_2016[$1];
END
for(i in guest_2016)
print i > "former_guests.txt"
' guests-2016.txt guests-2017.txt
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Check, does it do the job. I can add an explanation, if you are needed.
awk '
/^$/next
FNR == NR guest_2016[$1] = 1
FNR != NR
if(!guest_2016[$1])
print $1 > "new_guests.txt"
delete guest_2016[$1];
END
for(i in guest_2016)
print i > "former_guests.txt"
' guests-2016.txt guests-2017.txt
Check, does it do the job. I can add an explanation, if you are needed.
awk '
/^$/next
FNR == NR guest_2016[$1] = 1
FNR != NR
if(!guest_2016[$1])
print $1 > "new_guests.txt"
delete guest_2016[$1];
END
for(i in guest_2016)
print i > "former_guests.txt"
' guests-2016.txt guests-2017.txt
answered Sep 26 '17 at 20:41
MiniMax
2,706719
2,706719
add a comment |Â
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%2f394612%2fbash-script-for-showing-difference-between-two-text-files%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
6
Check out the manual page for
comm
. Then add what you have tried, and explain how it did not work as you intended.â DopeGhoti
Sep 26 '17 at 19:09