Re: compare files

"Scott Walters [email protected] [sed-users]" <[email protected]> Tue, 10 Jan 2017 04:56:18 +0000 (UTC)
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
Two points
1)  The below solution loads both the files initially into PS at firstand then works on it by removing line after line.
A better original approach would be to load  the smaller file first and just one line from the larger file and then working on it. Let us name the FileA.txt as the "keys" file and the FileB.txt as the "data" file.
My guess is that normally keys file is small and data file is large.either way below are two methods for the two cases. In both these methodswe load the smaller file and 1 line from the larger file.if not sure abt the size of the file any method can be used.
Method - a) ( keys file < data file)  Usage:  sed -f ab.sed FileA.txt FileB.txt
 #--------Begin  ab.sed ------------- $!{ N; /\n(/{ s/^/\n/; s/\n(\(\([^,]*,\)\{3\}\)\( *\)'\([^']*\)'/\n(\1\3_'\4'_/;    h; x; y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/; s/.*\n\([^;]*\);\([12]\);.*_'\1'_.*/\2/; /^[12]$/!s/.*/0/; x;  G; 
 s/^\n\(.*\)\n(\(.*\)_'.*'_\(.*\)\n\(.\)$/(\2'\4'\3\n\1/; P; } /^(/!s/^/\n/; D; } d; #-------------End--------------
Method - b) ( data file < keys file)
 Usage:  sed -f ba.sed FileB.txt FileA.txt
 #--------Begin  ba.sed ------------- /\n[^(]/!{ h; x; y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; s/^.*'\([^']*\)',[^,]*,[^,]*).*$/\1/;  x; G; s/^\(.*\)'\([^']*\)',\([^,]*\),\([^,]*\))\(.*\)\n\(.*\)$/\1'\6',\3,\4)\5/; }
 /\n[^(]/{  :loop {} /^\(.*\)(\(\([^,]*,\)\{3\}\)\( *\)'\([^']*\)'\([^)]*\))\(.*\)\n\5;\([12]\);$/{ s//\1(\2\4'\8'\6)\7\n\5;\8;/; bloop; } s/^\(.*\)\n.*/\1/; }
 $s/(\(\([^,]*,\)\{3\}\)\( *\)'\([a-zA-Z]*\)'/(\1\3'0'/g;  N;  s/^/\n/; D; #-------------End--------------


2) everyone nowadays uses GNU based sed. so [^\n] from the my previous solution   shouldnt be a problem. so while using posix based sed all you have to    replace [^\n] as    [^   ].
thanksSW 

    On Tuesday, January 10, 2017 2:20 AM, "[email protected] [sed-users]" <[email protected]> wrote:
 

     Yet another way where we can instead of lugging around the files A & B into the pattern space till the end, print the mapped lines of fileB and clear em from the P.S. soon as they get mapped looking at fileA. 
 Also note that the [^\n] regex is not Posix and so is avoided.
 

 usage: sed -f run.sed fileB.txt fileA.txt
 

 

 :read

 $bend
 N
 bread
 :end
 h
 y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
 s/^//;treset
 :reset
 s/^\([^,]*,\)\{3\}[ ]*'\([^']*\)'.*\n\(.*\n\)\{0,1\}\2;\([12]\);.*/\4/;tmap
 s/.*/0/
 :map
 x;H;g
 s/^\(.\)\n\(\([^,]*,\)\{3\}[ ]*\)'\([^']*\)'/\2'\1'/
 /^(/!d
 P;D
 #################################################

 

 




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

  #yiv8674535944 #yiv8674535944 -- #yiv8674535944ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv8674535944 #yiv8674535944ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv8674535944 #yiv8674535944ygrp-mkp #yiv8674535944hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv8674535944 #yiv8674535944ygrp-mkp #yiv8674535944ads {margin-bottom:10px;}#yiv8674535944 #yiv8674535944ygrp-mkp .yiv8674535944ad {padding:0 0;}#yiv8674535944 #yiv8674535944ygrp-mkp .yiv8674535944ad p {margin:0;}#yiv8674535944 #yiv8674535944ygrp-mkp .yiv8674535944ad a {color:#0000ff;text-decoration:none;}#yiv8674535944 #yiv8674535944ygrp-sponsor #yiv8674535944ygrp-lc {font-family:Arial;}#yiv8674535944 #yiv8674535944ygrp-sponsor #yiv8674535944ygrp-lc #yiv8674535944hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv8674535944 #yiv8674535944ygrp-sponsor #yiv8674535944ygrp-lc .yiv8674535944ad {margin-bottom:10px;padding:0 0;}#yiv8674535944 #yiv8674535944actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv8674535944 #yiv8674535944activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv8674535944 #yiv8674535944activity span {font-weight:700;}#yiv8674535944 #yiv8674535944activity span:first-child {text-transform:uppercase;}#yiv8674535944 #yiv8674535944activity span a {color:#5085b6;text-decoration:none;}#yiv8674535944 #yiv8674535944activity span span {color:#ff7900;}#yiv8674535944 #yiv8674535944activity span .yiv8674535944underline {text-decoration:underline;}#yiv8674535944 .yiv8674535944attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv8674535944 .yiv8674535944attach div a {text-decoration:none;}#yiv8674535944 .yiv8674535944attach img {border:none;padding-right:5px;}#yiv8674535944 .yiv8674535944attach label {display:block;margin-bottom:5px;}#yiv8674535944 .yiv8674535944attach label a {text-decoration:none;}#yiv8674535944 blockquote {margin:0 0 0 4px;}#yiv8674535944 .yiv8674535944bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv8674535944 .yiv8674535944bold a {text-decoration:none;}#yiv8674535944 dd.yiv8674535944last p a {font-family:Verdana;font-weight:700;}#yiv8674535944 dd.yiv8674535944last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv8674535944 dd.yiv8674535944last p span.yiv8674535944yshortcuts {margin-right:0;}#yiv8674535944 div.yiv8674535944attach-table div div a {text-decoration:none;}#yiv8674535944 div.yiv8674535944attach-table {width:400px;}#yiv8674535944 div.yiv8674535944file-title a, #yiv8674535944 div.yiv8674535944file-title a:active, #yiv8674535944 div.yiv8674535944file-title a:hover, #yiv8674535944 div.yiv8674535944file-title a:visited {text-decoration:none;}#yiv8674535944 div.yiv8674535944photo-title a, #yiv8674535944 div.yiv8674535944photo-title a:active, #yiv8674535944 div.yiv8674535944photo-title a:hover, #yiv8674535944 div.yiv8674535944photo-title a:visited {text-decoration:none;}#yiv8674535944 div#yiv8674535944ygrp-mlmsg #yiv8674535944ygrp-msg p a span.yiv8674535944yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv8674535944 .yiv8674535944green {color:#628c2a;}#yiv8674535944 .yiv8674535944MsoNormal {margin:0 0 0 0;}#yiv8674535944 o {font-size:0;}#yiv8674535944 #yiv8674535944photos div {float:left;width:72px;}#yiv8674535944 #yiv8674535944photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv8674535944 #yiv8674535944photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv8674535944 #yiv8674535944reco-category {font-size:77%;}#yiv8674535944 #yiv8674535944reco-desc {font-size:77%;}#yiv8674535944 .yiv8674535944replbq {margin:4px;}#yiv8674535944 #yiv8674535944ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv8674535944 #yiv8674535944ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv8674535944 #yiv8674535944ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv8674535944 #yiv8674535944ygrp-mlmsg select, #yiv8674535944 input, #yiv8674535944 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv8674535944 #yiv8674535944ygrp-mlmsg pre, #yiv8674535944 code {font:115% monospace;}#yiv8674535944 #yiv8674535944ygrp-mlmsg * {line-height:1.22em;}#yiv8674535944 #yiv8674535944ygrp-mlmsg #yiv8674535944logo {padding-bottom:10px;}#yiv8674535944 #yiv8674535944ygrp-msg p a {font-family:Verdana;}#yiv8674535944 #yiv8674535944ygrp-msg p#yiv8674535944attach-count span {color:#1E66AE;font-weight:700;}#yiv8674535944 #yiv8674535944ygrp-reco #yiv8674535944reco-head {color:#ff7900;font-weight:700;}#yiv8674535944 #yiv8674535944ygrp-reco {margin-bottom:20px;padding:0px;}#yiv8674535944 #yiv8674535944ygrp-sponsor #yiv8674535944ov li a {font-size:130%;text-decoration:none;}#yiv8674535944 #yiv8674535944ygrp-sponsor #yiv8674535944ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv8674535944 #yiv8674535944ygrp-sponsor #yiv8674535944ov ul {margin:0;padding:0 0 0 8px;}#yiv8674535944 #yiv8674535944ygrp-text {font-family:Georgia;}#yiv8674535944 #yiv8674535944ygrp-text p {margin:0 0 1em 0;}#yiv8674535944 #yiv8674535944ygrp-text tt {font-size:120%;}#yiv8674535944 #yiv8674535944ygrp-vital ul li:last-child {border-right:none !important;}#yiv8674535944 

   

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