Re: split column

"Thierry Blanc [email protected] [sed-users]" <[email protected]> Tue, 29 Mar 2016 19:59:37 +0200
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
we can shorten ...

sed -r 's|;|\n|5;s|;|\n|5;s|\n([ 0-9]*)([a-zA-Z ]*)\n|;\1;\2;|'   

 1. replace the 5th separator with mark
 2. replace the 6th! separator (6th becomes 5th after line above) with mark
 3. add semicolon and reverse the markers

spaces remain as is.

On 29/03/16 09:48, MOKRANI Rachid [email protected] [sed-users] wrote:
> Hi,
>
> Do you have a simple proposal with sed / awk.
>
> In this  exemple, need to split column 7
>
> Company A  ;   NAME A  ;  FIRSTNAME 1  ;  JOB 1  ;  Town 1  ;   145854 abVFrd  ;  COMMENT 1  ;
>
>
>
> And obtain 8 columns (7 always a number - 8 always alphabetic)
>
> Company A  ;  NAME A  ;  FIRSTNAME 1  ;  JOB 1  ;  Town 1  ;   145854 ; abVFrd  ;  COMMENT 1  ;
>
>
>
> But sometime the colum 7 can have
> ;  145854 abVFrd ;
> Need to have
> ; 145854 ; abVFrd;
>
> ; 145854;
> Need to have
> ; 145854; ;
>
>
> ; abVFrd;
> Need to have
> ;  ; abVFrd;
>
>
> ; ;
> Need to have
> ; ; ;
>
>
>
>
>
> Company A;NAME A;FIRSTNAME 1;JOB 1;Town 1; 145854 abVFrd;COMMENT 1;
>
> Company A;NAME A;FIRSTNAME 4;JOB 1;Town ;145862 dsfsd; COMMENT 5;
>
> Company B;NAME T ;FIRSTNAME 1;JOB 2;Town 2;ABGHKYH; COMMENT 1235;
>
> Company C;NAME M;FIRSTNAME 2;JOB 7;Town 1;259874; COMMENT 4;
>
> Company Y;NAME G;FIRSTNAME 4;JOB 52;Town 1;; COMMENT 1;
>
> Company Y;NAME F ;FIRSTNAME 8;JOB 82;Town 3;125478; COMMENT 15;
>
>
>
> Need to obtain the result below.
>
>
>
> Company A;NAME A;FIRSTNAME 1;JOB 1;Town 1; 145854;abVFrd;COMMENT 1;
>
> Company A;NAME A;FIRSTNAME 4;JOB 1;Town ;145862;dsfsd; COMMENT 5;
>
> Company B;NAME T ;FIRSTNAME 1;JOB 2;Town 2;;ABGHKYH; COMMENT 1235;
>
> Company C;NAME M;FIRSTNAME 2;JOB 7;Town 1;259874;; COMMENT 4;
>
> Company Y;NAME G;FIRSTNAME 4;JOB 52;Town 1;;; COMMENT 1;
>
> Company Y;NAME F ;FIRSTNAME 8;JOB 82;Town 3;125478;; COMMENT 15;
>
>
>
> Thanks,
> 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]