RE: sed/awk convert lines to colum

"MOKRANI Rachid" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
Hi,

Many many thanks, it's working. I have an other suggestion.



And if I would like to reduce the number of text (text1 and text2) colums , do you have the magic command ?

id 	; 	text	 		
1	;	AAAA
1	;	AA BB CC
1	;	CC 22 2DS
1	;	45 H DE T
2	;	WW NN FDRET
2	;	ZZZ DS 05 K
2	;	ss sss ss ss ssss
3	;	7584455 tedr dr
3	;	JH CD FER GT 544 . 45
...

I would like to have with sed/awk the following result

id	;	text1	        ; text2              
1	;	AAAA	        ; AA BB CC (space or other) CC 22 2DS (space or other)45 H DE T
2	;   WW NN FDRET     ; ZZZ DS 05 K (space or other) ss sss ss ss ssss
3	;   7584455 tedr dr ; JH CD FER GT 544 . 45
...
...
...


Any suggestion.
Thanks in advance.







> -----Message d'origine-----
> De : Tim Chase [mailto:[email protected]] 
> Envoyé : mardi 4 décembre 2012 13:31
> À : MOKRANI Rachid
> Cc : [email protected]
> Objet : Re: sed/awk convert lines to colum
> 
> On 12/04/12 06:07, MOKRANI Rachid wrote:
> > id 	; 	text	 		
> > 1	;	AAAA
> > 1	;	AA BB CC
> > 1	;	CC 22 2DS
> > 1	;	45 H DE T
> > 2	;	WW NN FDRET
> > 2	;	ZZZ DS 05 K
> > 2	;	ss sss ss ss ssss
> > 3	;	7584455 tedr dr
> > 3	;	JH CD FER GT 544 . 45
> > ...
> > 
> > I would like to have with sed/awk the following result
> > 
> > id	;	text1	       ;  text2               ;	text3
> > ;	text4  	;	text5	;	text6 .......
> > 1	;	AAAA	       ; AA BB CC             ;	CC 22 2DS
> > ;  45 H DE T
> > 2	;   WW NN FDRET    ; ZZZ DS 05 K          ;  ss sss ss ss ssss
> > 3	;   7584455 tedr dr; JH CD FER GT 544 . 45
> 
> I *think* you want to take any adjacent lines that start with the
> same ID and combine them into one line, separated by additional
> semicolons.  However, somehow you magically are adding an arbitrary
> number of headers before you've seen the rest of the file.  If it's
> just combining the adjacent same lines, the following works for me:
> 
>  sed -n -e '$!{:a;N;s/^\([0-9]\+\)\(.*\)\n\1\s/\1\2/;$p;ta;P;D;$p;ba}'
> 
> I suppose you could insert the headers manually if you knew many you
> wanted to include:
> 
> sed -n -e"1s/.*/&; text2; text3; text4; text5; text6/" -e
> '$!{:a;N;s/^\([0-9]\+\)\(.*\)\n\1\s/\1\2/;$p;ta;P;D;$p;ba}'
> 
> Beware that odd things happen if your file only contains two lines
> (one header + one line of data).
> 
> -tkc
> 
> 
> 
> 
__________________________
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.
__________________________
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.