| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
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]