Re: help for concatenate 2 files
Werfgam Nadler <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
I guess i was just trying to solve the problem entirely with sed and not to use several other commands. my comments for my code are below. W ________________________________ From: Thierry Blanc <[email protected]> To: Werfgam Nadler <[email protected]> Cc: MOKRANI Rachid <[email protected]>; "[email protected]" <[email protected]> Sent: Wednesday, April 17, 2013 10:27 PM Subject: Re: help for concatenate 2 files other solution: sed -r 's|([^;]*)\s*;.*|\1;TEST;TEST|' file1 |cat file2 - |sort -n |uniq -w 5 | cut -c 5- | paste file1 - file1: file that has ALL entries file2: file that has just the additional entries (i.e. not line 8 and 13) On 04/17/2013 08:05 AM, Werfgam Nadler wrote: > Hi, > > try this solution. > > cat file1 file2 | sed ' # Read all the content of both the files. > $!{ > N; > s/^/\n/; > D > } # If two lines without same bug_id exist then.... > /^\([^\n; ]*\) .*\n\1 /!{ > s/\n/; TEST ; TEST ;&/ > /\n/!s/$/; TEST ; TEST ;/ > } #if two lines with same bug id (assuming it is just not a number). exists. then... > /^\([^\n; ]*\)\( *\);\([^\n][^\n]*\)\(.*\)\n\1 *\([^\n][^\n]*\)/{ > s//\1\2;\3\5\4/; > } > P; > D; > ' > > I got the below result > > bug_id ; creation_ts ; bug_severity; bug_when ; added > 8 ; 2013-03-21 ; N/A; TEST ; TEST ; > 9 ; 2013-03-21 ; Mineur; 2013-03-21 15:49:44 ; CONFIRME > 10 ; 2013-03-21 ; Mineur; 2013-03-21 15:04:56 ; CONFIRME > 11 ; 2013-03-21 ; Mineur; 2013-03-21 15:56:59 ; CONFIRME > 12 ; 2013-03-25 ; N/A; 2013-03-25 17:09:09 ; CONFIRME > 13 ; 2013-03-25 ; N/A; TEST ; TEST ; > > > thanks > WN > > > > > > ________________________________ > From: MOKRANI Rachid <[email protected]> > To: [email protected] > Sent: Wednesday, March 27, 2013 8:32 PM > Subject: help for concatenate 2 files > > > Hi, > > I don't know how to concatenate two files with row. > > The first file is : > > cat /tmp/file1 > > bug_id ; creation_ts ; bug_severity > 8 ; 2013-03-21 ; N/A > 9 ; 2013-03-21 ; Mineur > 10 ; 2013-03-21 ; Mineur > 11 ; 2013-03-21 ; Mineur > 12 ; 2013-03-25 ; N/A > 13 ; 2013-03-25 ; N/A > > The second file is : > > cat /tmp/file2 > > bug_id ; bug_when ; added > 9 ; 2013-03-21 15:49:44 ; CONFIRME > 10 ; 2013-03-21 15:04:56 ; CONFIRME > 11 ; 2013-03-21 15:56:59 ; CONFIRME > 12 ; 2013-03-25 17:09:09 ; CONFIRME > > > I don't know how to obtain the following result . > > bug_id ; creation_ts ; bug_severity ; bug_when ; added ; > 8 ; 2013-03-21 ; N/A ; ; ; > 9 ; 2013-03-21 ; Mineur ; 2013-03-21 15:49:44 ; CONFIRME ; > 10 ; 2013-03-21 ; Mineur ; 2013-03-21 15:04:56 ; CONFIRME ; > 11 ; 2013-03-21 ; Mineur ; 2013-03-21 15:56:59 ; CONFIRME ; > 12 ; 2013-03-25 ; N/A ; 2013-03-25 17:09:09 ; CONFIRME ; > 13 ; 2013-03-25 ; N/A ; ; ; > > OR the following > > bug_id ; creation_ts ; bug_severity ; bug_when ; added ; > 8 ; 2013-03-21 ; N/A ; TEST ; TEST ; > 9 ; 2013-03-21 ; Mineur ; 2013-03-21 15:49:44 ; CONFIRME ; > 10 ; 2013-03-21 ; Mineur ; 2013-03-21 15:04:56 ; CONFIRME ; > 11 ; 2013-03-21 ; Mineur ; 2013-03-21 15:56:59 ; CONFIRME ; > 12 ; 2013-03-25 ; N/A ; 2013-03-25 17:09:09 ; CONFIRME ; > 13 ; 2013-03-25 ; N/A ; TEST ; TEST ; > > > Any help will be really appreciate. > Best regards. > > > ------------------------------------ > ------------------------------------ -- Yahoo! Groups Links [Non-text portions of this message have been removed]