Re: join two files

"Ruud H.G. van Tol" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
In Perl:

perl -wpe '
   BEGIN{%h=map{split/\s*;\s*/}`cat ./file1`}
   s/((\S+).*)/"$1 ".($h{$2}||"N\/A")/e
' ./file2

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


Make it:

   /"$1 ".($h{$2}||"N\/A")." ;"/

if you need the trailing " ;".

-- 
Ruud
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.