Link to home
Start Free TrialLog in
Avatar of Watnog
WatnogFlag for Belgium

asked on

Bash: write differences of 2 files to seperate files

Dear Experts,

I need 2 files compared on columns 13 and 14 (example: first line of first file > 3405143 5954504 ), and the differences written in seperated files.

If in file1 and not in file2 then write that line to "gone.txt" file.
If in file2 and not in file1 the write that line to "new.txt" file
If in file 1 and in file2 write that line in "stillthere.txt" file

file1
IN0R0300 IN0R0301_P P_IN56CEXP ABORTED 02/21/2020 065000 02/21/2020 070258 LBKL203 SYS_BATCH 000000 100 3405143 5954504 02/21/2020 epk 000 000 00 5407344 Launching Thaler XNINMLT MLTL_F1344914 W6 0000
IN0R0040 IN0R0041_P P_IN56CEXP ABORTED 02/21/2020 090623 02/21/2020 091224 LBKL203 SYS_BATCH 000000 100 3405585 5956805 02/21/2020 epk 000 000 00 5409565 file MBRS_20200221060228494_be07001648317966.edi 0000
IN0R0040 IN0R0041_P P_IN56CEXP ABORTED 02/21/2020 091344 02/21/2020 091458 LBKL203 SYS_BATCH 000000 100 3405615 5956984 02/21/2020 epk 000 000 00 5409747 file MBRS_20200221060234621_be02001352669040.edi 0000
IN0R0040 IN0R0041_P P_IN56CEXP ABORTED 02/21/2020 091714 02/21/2020 092555 LBKL203 SYS_BATCH 000000 100 3405628 5957067 02/21/2020 epk 000 000 00 5409826 file MBRS_20200221060308372_be46001027379136.edi 0000

Open in new window


file2
FT0Y7100 FT0Y7100_P P_FT56CEXP ABORTED 02/21/2020 000002 02/21/2020 000002 LBKL203 SYS_BATCH 000000 100 3399102 5948246 02/21/2020 epk 000 000 00 5401245 chain's name: FT0Y7100 0000
IN0R0300 IN0R0301_P P_IN56CEXP ABORTED 02/21/2020 065000 02/21/2020 070258 LBKL203 SYS_BATCH 000000 100 3405143 5954504 02/21/2020 epk 000 000 00 5407344 Launching Thaler XNINMLT MLTL_F1344914 W6 0000
ZMKTRCOD ZMX0850001 T_TH56CEXP ABORTED 02/21/2020 155227 02/21/2020 155227 LBKL203 SYS_BATCH 000000 100 3406949 5963705 02/21/2020 epk 000 000 00 5416287 chain's name: ZMKTRCOD
IN0R0310 IN0R0311_P P_IN56CEXP ABORTED 02/21/2020 160001 02/21/2020 160246 LBKL203 SYS_BATCH 000000 100 3406974 5963820 02/21/2020 epk 000 000 00 5416396 Launching Thaler XNIN109 IML_F1347154 W2 0000

Open in new window


Many thanks.
W
Avatar of Arana (G.P.)
Arana (G.P.)

I dont understand how you want to determine what output file to use,

"If in file1 and not in file2 "   both files have a line 1, both files have values that are not in the other file, so what to do?

file1   3405143 5954504
file2   3399102 5948246

in this case what goes where? please explain.
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Watnog

ASKER

Pearl! Thank you Noci, your script does do it very well.
Cheers, Have a great weekend.
np. same for you.
hmm ok after running the script now I understand what you wanted, but Im not sure what happens with
this line (line 3 in file1):
IN0R0040 IN0R0041_P P_IN56CEXP ABORTED 02/21/2020 091344 02/21/2020 091458 LBKL203 SYS_BATCH 000000 100 3405615 5956984 02/21/2020 epk 000 000 00 5409747 file MBRS_20200221060234621_be02001352669040.edi 0000

Open in new window

Shouldnt it go to "Gone"?  (the script ignored it, didn't save it in any of the files)

nevermind I added an extra LF on file 1 and then it worked
Avatar of Watnog

ASKER

👌