Re: join two files
Werfgam Nadler <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
here is a solution.
sed '
$!{
N;
s/^/\n/;
D
}
/^\([^\n; ]*\)\( *\);.*\n\1\( *\);/!{
s/\n/ N\/A ;&/
/\n/!s/$/ N\/A;/
}
/^\([^\n; ]*\)\( *\);\([^\n][^\n]*\)\(.*\)\n\1\( *\);\([^\n][^\n]*\)/{
s//\1\2;\3 \6\5\4/;
}
P;
D;
' file2 file1
# PS : it is ur file2 and file1 in that order.
this gives the solution below.
Num ; Comments ; Nbr_pass;
1 ; AAAA ; N/A ;
2 ; BBBBB ; N/A ;
3 ; CC ; N/A ;
4 ; XXDF ; N/A ;
5 ; KIJHG ; 1;
6 ; GFRD ; N/A ;
7 ; HGTFEDFR ; 1;
8 ; DJHY ; 4;
9 ; FDGRTFG ; N/A ;
10 ; QWXVG ; N/A ;
11 ; FTGJ ; N/A ;
12 ; DHGRF ; 1;
13 ; GFDRFE ; 5;
14 ; GFDRFE ; N/A ;
15 ; FGTF ; 7;
16 ; LKJU ; N/A ;
17 ; DFDE ; N/A;
________________________________
From: MOKRANI Rachid <[email protected]>
To: [email protected]
Sent: Wednesday, May 15, 2013 5:25 PM
Subject: join two files
Hi,
I need some help for doing the following command with sed. Is someone
could gibe me the exemple ?
Many thanks.
=============================
cat /tmp/file_1
Num;Nbr_pass;
5;1;
7;1;
8;4;
12;1;
13;5;
15;7;
=============================
cat /tmp/file2
Num ; Comments ;
1 ; AAAA ;
2 ; BBBBB ;
3 ; CC ;
4 ; XXDF ;
5 ; KIJHG ;
6 ; GFRD ;
7 ; HGTFEDFR ;
8 ; DJHY ;
9 ; FDGRTFG ;
10 ; QWXVG ;
11 ; FTGJ ;
12 ; DHGRF ;
13 ; GFDRFE ;
14 ; GFDRFE ;
15 ; FGTF ;
16 ; LKJU ;
17 ; DFDE ;
=============================
The result, I would like to have.
Num ; Comments ; Nbr_pass ;
1 ; AAAA ; N/A ;
2 ; BBBBB ; N/A;
3 ; CC ; N/A;
4 ; XXDF ; N/A;
5 ; KIJHG ;1 ;
6 ; GFRD ; N/A;
7 ; HGTFEDFR ; 1 ;
8 ; DJHY ; 1 ;
9 ; FDGRTFG ; N/A;
10 ; QWXVG ; N/A;
11 ; FTGJ ; N/A;
12 ; DHGRF ; 1 ;
13 ; GFDRFE ; 5 ;
14 ; GFDRFE ; N/A;
15 ; FGTF ; 7 ;
16 ; LKJU ; N/A;
17 ; DFDE ; N/A;
Many thanks for help.
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]
------------------------------------
--
Yahoo! Groups Links
[Non-text portions of this message have been removed]