| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
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
On 06/01/17 16:25, MOKRANI Rachid [email protected] [sed-users] wrote:
> 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]
>
>
>
> ------------------------------------
> Posted by: MOKRANI Rachid <[email protected]>
> ------------------------------------
>
[Non-text portions of this message have been removed]