Discussion:
compare files
MOKRANI Rachid rachid.mokrani@ifpen.fr [sed-users]
2017-01-06 12:55:35 UTC
Permalink
Hi,

Before to ask my firts question of the year.
Happy new year to all !


Then,
I have some difficulties to compare two files with with many arguments.



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]
Thierry Blanc Thierry.Blanc@gmx.ch [sed-users]
2017-01-06 14:58:46 UTC
Permalink
first:

* all names are lower case, there is no EXACT match. I assume that the
names start with upper case
* dominique;1 2; probably a typo

Create intermediary sed script.

first run

sed -rf sedfile A.txt > tmp.sed

sedfile:

s?(.*);(.*);?/([^,]*,[^,]*,[^,]*,) '\1'/s||\\1 '\2'|?

(better as a script because of quotes)
this creates a temporary sed script.

then run

sed -rf tmp.sed B.txt >temp.txt

this will replace all occurences

then run
sed -rf sed2 temp.txt

sed2:

/[0-9]/!s|([^,]*,[^,]*,[^,]*,) '[A-Za-z]*'|\1 '0'|

this will change all lines where nothing was found in file A.txt
Post by MOKRANI Rachid ***@ifpen.fr [sed-users]
Hi,
Before to ask my firts question of the year.
Happy new year to all !
Then,
I have some difficulties to compare two files with with many arguments.
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]
Thierry Blanc Thierry.Blanc@gmx.ch [sed-users]
2017-01-06 15:04:51 UTC
Permalink
a much easier approach is a while loop in bash

sed 's|(||;s|)||' B.txt | while IFS=',' read A B C D E F
do

# do the testing here, $A to $F... are your fields in the file
echo " ( '$A' , '$B', ...

done

... but it is slow.
Post by MOKRANI Rachid ***@ifpen.fr [sed-users]
Hi,
Before to ask my firts question of the year.
Happy new year to all !
Then,
I have some difficulties to compare two files with with many arguments.
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]
------------------------------------
------------------------------------
sharma__r@hotmail.com [sed-users]
2017-01-08 12:47:46 UTC
Permalink
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 sed-***@yahoogroups.com, <***@...> 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]
Scott Walters scott_walters36@yahoo.com [sed-users]
2017-01-08 17:36:51 UTC
Permalink
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, "***@hotmail.com [sed-users]" <sed-***@yahoogroups.com> 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 sed-***@yahoogroups.com, <***@...> 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]
sharma__r@hotmail.com [sed-users]
2017-01-09 20:50:25 UTC
Permalink
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]
Scott Walters scott_walters36@yahoo.com [sed-users]
2017-01-10 04:56:18 UTC
Permalink
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, "***@hotmail.com [sed-users]" <sed-***@yahoogroups.com> 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]

Loading...