Re: compare files

"Scott Walters [email protected] [sed-users]" <[email protected]> Sun, 8 Jan 2017 17:36:51 +0000 (UTC)
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
hi all,
NOT making any of those assumptions in the previous mail, the solution is belowuse it as follows . sed -f abc.sed FileA.txt FileB.txt

#-------Begin abc.sed-------# $!{ N; s/^/\n/; D; }
 s/^/\n/; s/(/\n&/; # can use the first occurence of '(' as the seperation of two files.
 s/\n(\(\([^,]*,\)\{3\}\)\( *\)'\([^']*\)'/\n(\1\3_'\4'_/g;
 :loop1 {} h;x;  y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;  /.*\n\([^;]*\);\([12]\);.*\n\n[^\n]*_'\1'_.*/{ s//\2/; x;  G; s/_'\([^']*\)'_\(.*\)\n\(.\)$/'\3'\2/; ba; } x; s/\n\n\([^\n]*\)_'[^\n]*'_/\n\n\1'0'/;
 :a {} s/\n\n\([^\n]*\)/\n\1\n/; /\n$/!bloop1;
 s/^[^(]*//; s/.$//;#-------------End-------------#
thanks
SW

    On Sunday, January 8, 2017 6:17 PM, "[email protected] [sed-users]" <[email protected]> wrote:
 

     Firstly the fileA.txt files have names in all lowercase and hence a complete match with fileB.txt is never gonna happen. Hence I assumed this to be a typo. Second, there's a missing "," at the end of the first record which again
 was taken as a typo by me.
 And since "sed" doesnot have a concept of FNR of awk whereby we can allow multifile processing to go smoothly I have added a dummy char "." at the end of the fileA.txt to enable "sed" to know that fileA.txt has ended now.
 

 With these 3 things kept in mind, we can do all the required work in just
 1 sed invocation like as given below:
 

 ### store the contents of the below sed code in a file "fx.sed"
 Then invoke "sed" with the file arguments in the order specified:
 sed -f fx.sed fileA.txt fileB.txt
 

 fx.sed is needed as it involves ! and ' chars which are special to the
 shells and will need quoting thereby complicating the lookNfeel of the already clumsy code even more. Also, placing it in a file makes the job portable when we need to run more than once and not on the same day.
 

 

 # readin the contents of fileA into hold space
 1{
 :loop
 N
 /\n[^;]*;[12];$/!s/\n[^;]*;[^;]*;$//
 /\n\.$/!bloop
 s///
 h
 d
 }
 

 # mark the 4th field
 s/^/,/
 s/,/\n/4
 s/,/\n/4
 

 G
 s/^,//;tdummy
 :dummy
 

 s/\(\n[ ]*\)'\([^']*\)'\([ ]*\n.*\)\n\2;\([12]\);/\1'\4'\3/;ta
 s/\(\n[ ]*\)'\([^']*\)'\([ ]*\n\)/\1'0'\3/
 

 # remove all but the 3rd newline to enable the removal of hold space
 :a
 s/\n//4
 ta
 

 s/\(.*\)\n.*/\1/; # remove the hold space
 y/\n/,/; # replace the markers
 ######### EOF #######
 

 HTH&
 HNY

 

---In [email protected], <rachid.mokrani@...> wrote :

 File A.txt
 
 henry;1;
 christophe;1;
 bill;1;
 nathalie;2;
 jane;2;
 william;1;
 dominique;1 2;
 pierre-henry;1;
 
 
 File B.txt
 
 ( 'TA', 'Christophe', 'Jane', 'Christophe', 'US', 'New York')
 ( 'XA', 'Dominique', 'Grant', 'Dominique', 'US', 'New York'),
 ( 'XA', 'Bill', 'Jane', 'Bill', 'US', 'New York'),
 ( 'BC', 'Nathalie', 'Portman', 'Nathalie', 'US', 'New York'),
 ( 'BC', 'Pierre', 'Robert', 'Pierre', 'US', 'New York'),
 ( 'XV', 'Jane', 'Fonda', 'Jane', 'IT', 'Roma'),
 ( 'HG', 'William', 'Jefferson', 'William', 'US', 'Chicago'),
 ( 'HG', 'Barberousse', 'Pirate', 'Barberousse', 'US', 'Chicago'),
 ( 'XA', 'Henry', 'Grant', 'Henry', 'US', 'Miami'),
 
 
 
 In file B, if the EXACT content of the colum 4 exist in the first colum in the file A.txt, then replace it with the value of the second colum of the file A.txt . it should be only 1 OR 2
 
 And
 
 In file B, if the EXACT content of the colum 4 does not exist in the first colum in the file A.txt, then replace the value of the fourth colum of the file B.txt with 0 .
 
 
 
 
 I hope to be clear...
 
 
 Here is the expected result in the example I have just given
 
 
 Need Result.
 ( 'TA', 'Christophe', 'Jane', '1', 'US', 'New York')
 ( 'XA', 'Dominique', 'Grant', '0', 'US', 'New York'),
 ( 'XA', 'Bill', 'Jane', '1', 'US', 'New York'),
 ( 'BC', 'Nathalie', 'Portman', '2', 'US', 'New York'),
 ( 'BC', 'Pierre', 'Robert', '0', 'US', 'New York'),
 ( 'XV', 'Jane', 'Fonda', '2', 'IT', 'Roma'),
 ( 'HG', 'William', 'Jefferson', '1', 'US', 'Chicago'),
 ( 'HG', 'Barberousse', 'Pirate', '0', 'US', 'Chicago'),
 ( 'XA', 'Henry', 'Grant', '1', 'US', 'Miami'),
 
 
 Any suggestions ?
 
 Best regards,
 __________________________ 
 Avant d'imprimer, pensez à l'environnement ! Please consider the environment before printing ! 
 Ce message et toutes ses pièces jointes sont confidentiels et établis à l'intention exclusive de ses destinataires. Toute utilisation non conforme à sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. IFP Energies nouvelles décline toute responsabilité au titre de ce message. This message and any attachments are confidential and intended solely for the addressees. Any unauthorised use or dissemination is prohibited. IFP Energies nouvelles should not be liable for this message. 
 __________________________
 
 
 [Non-text portions of this message have been removed]



[Non-text portions of this message have been removed]

  #yiv1821957888 #yiv1821957888 -- #yiv1821957888ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv1821957888 #yiv1821957888ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv1821957888 #yiv1821957888ygrp-mkp #yiv1821957888hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv1821957888 #yiv1821957888ygrp-mkp #yiv1821957888ads {margin-bottom:10px;}#yiv1821957888 #yiv1821957888ygrp-mkp .yiv1821957888ad {padding:0 0;}#yiv1821957888 #yiv1821957888ygrp-mkp .yiv1821957888ad p {margin:0;}#yiv1821957888 #yiv1821957888ygrp-mkp .yiv1821957888ad a {color:#0000ff;text-decoration:none;}#yiv1821957888 #yiv1821957888ygrp-sponsor #yiv1821957888ygrp-lc {font-family:Arial;}#yiv1821957888 #yiv1821957888ygrp-sponsor #yiv1821957888ygrp-lc #yiv1821957888hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv1821957888 #yiv1821957888ygrp-sponsor #yiv1821957888ygrp-lc .yiv1821957888ad {margin-bottom:10px;padding:0 0;}#yiv1821957888 #yiv1821957888actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv1821957888 #yiv1821957888activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv1821957888 #yiv1821957888activity span {font-weight:700;}#yiv1821957888 #yiv1821957888activity span:first-child {text-transform:uppercase;}#yiv1821957888 #yiv1821957888activity span a {color:#5085b6;text-decoration:none;}#yiv1821957888 #yiv1821957888activity span span {color:#ff7900;}#yiv1821957888 #yiv1821957888activity span .yiv1821957888underline {text-decoration:underline;}#yiv1821957888 .yiv1821957888attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv1821957888 .yiv1821957888attach div a {text-decoration:none;}#yiv1821957888 .yiv1821957888attach img {border:none;padding-right:5px;}#yiv1821957888 .yiv1821957888attach label {display:block;margin-bottom:5px;}#yiv1821957888 .yiv1821957888attach label a {text-decoration:none;}#yiv1821957888 blockquote {margin:0 0 0 4px;}#yiv1821957888 .yiv1821957888bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv1821957888 .yiv1821957888bold a {text-decoration:none;}#yiv1821957888 dd.yiv1821957888last p a {font-family:Verdana;font-weight:700;}#yiv1821957888 dd.yiv1821957888last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv1821957888 dd.yiv1821957888last p span.yiv1821957888yshortcuts {margin-right:0;}#yiv1821957888 div.yiv1821957888attach-table div div a {text-decoration:none;}#yiv1821957888 div.yiv1821957888attach-table {width:400px;}#yiv1821957888 div.yiv1821957888file-title a, #yiv1821957888 div.yiv1821957888file-title a:active, #yiv1821957888 div.yiv1821957888file-title a:hover, #yiv1821957888 div.yiv1821957888file-title a:visited {text-decoration:none;}#yiv1821957888 div.yiv1821957888photo-title a, #yiv1821957888 div.yiv1821957888photo-title a:active, #yiv1821957888 div.yiv1821957888photo-title a:hover, #yiv1821957888 div.yiv1821957888photo-title a:visited {text-decoration:none;}#yiv1821957888 div#yiv1821957888ygrp-mlmsg #yiv1821957888ygrp-msg p a span.yiv1821957888yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv1821957888 .yiv1821957888green {color:#628c2a;}#yiv1821957888 .yiv1821957888MsoNormal {margin:0 0 0 0;}#yiv1821957888 o {font-size:0;}#yiv1821957888 #yiv1821957888photos div {float:left;width:72px;}#yiv1821957888 #yiv1821957888photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv1821957888 #yiv1821957888photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv1821957888 #yiv1821957888reco-category {font-size:77%;}#yiv1821957888 #yiv1821957888reco-desc {font-size:77%;}#yiv1821957888 .yiv1821957888replbq {margin:4px;}#yiv1821957888 #yiv1821957888ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv1821957888 #yiv1821957888ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv1821957888 #yiv1821957888ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv1821957888 #yiv1821957888ygrp-mlmsg select, #yiv1821957888 input, #yiv1821957888 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv1821957888 #yiv1821957888ygrp-mlmsg pre, #yiv1821957888 code {font:115% monospace;}#yiv1821957888 #yiv1821957888ygrp-mlmsg * {line-height:1.22em;}#yiv1821957888 #yiv1821957888ygrp-mlmsg #yiv1821957888logo {padding-bottom:10px;}#yiv1821957888 #yiv1821957888ygrp-msg p a {font-family:Verdana;}#yiv1821957888 #yiv1821957888ygrp-msg p#yiv1821957888attach-count span {color:#1E66AE;font-weight:700;}#yiv1821957888 #yiv1821957888ygrp-reco #yiv1821957888reco-head {color:#ff7900;font-weight:700;}#yiv1821957888 #yiv1821957888ygrp-reco {margin-bottom:20px;padding:0px;}#yiv1821957888 #yiv1821957888ygrp-sponsor #yiv1821957888ov li a {font-size:130%;text-decoration:none;}#yiv1821957888 #yiv1821957888ygrp-sponsor #yiv1821957888ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv1821957888 #yiv1821957888ygrp-sponsor #yiv1821957888ov ul {margin:0;padding:0 0 0 8px;}#yiv1821957888 #yiv1821957888ygrp-text {font-family:Georgia;}#yiv1821957888 #yiv1821957888ygrp-text p {margin:0 0 1em 0;}#yiv1821957888 #yiv1821957888ygrp-text tt {font-size:120%;}#yiv1821957888 #yiv1821957888ygrp-vital ul li:last-child {border-right:none !important;}#yiv1821957888 

   

[Non-text portions of this message have been removed]