Re: text substitution in a colum

Thierry Blanc <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
\t[^\t]*
means look for a tab followed by anything but a tab. Every column, 
except the first,  is separated by this. Just repeat it twice for the 
third column, 4x for the fifth, etc.

On 27/11/12 10:09, MOKRANI Rachid wrote:
> Hi,
>
> Many thanks for all. Below how to do to change ONLY the firt numéric colum.
>
>
> cat text.txt
> Title1  Title2  Title3  Title4  Title5
> AA      B       66      D       78
> B       BDS     7       TT      555
> VS      FDSE    53      TGF     1
> B       GF      5       GF      12548
>
> sed -r '2,$ s|(\t[^\t]*\t)([0-9]*)|\1MY_\2|' text.txt
> Title1  Title2  Title3  Title4  Title5
> AA      B       MY_66   D       78
> B       BDS     MY_7    TT      555
> VS      FDSE    MY_53   TGF     1
> B       GF      MY_5    GF      12548
>
>
>
> But how to do if I need to change ONLY the 5th colum.
>
> cat text.txt
> Title1  Title2  Title3  Title4  Title5 Title6   Title7
> AA      B       66      D       78      45      AA
> B       BDS     7       TT      555     6555    B
> VS      FDSE    53      TGF     1       2       QQ
> B       GF      5       GF      12548   12      WWWW
>
>
>
> Title1  Title2  Title3  Title4  Title5 Title6   Title7
> AA      B       66      D       MY_78      45      AA
> B       BDS     7       TT      MY_555     6555    B
> VS      FDSE    53      TGF     MY_1       2       QQ
> B       GF      5       GF      MY_12548   12      WWWW
>
>
>
>
>
>
>
>   
>
>> -----Message d'origine-----
>> Envoyé : mardi 27 novembre 2012 09:02
>> À : [email protected]
>> Objet : Re: text substitution in a colum
>>
>> if there are numbers in other columns than the 3rd, use that:
>>
>> sed -r '1!s|(\t[^\t]*\t)([0-9]*)|\1MY_\2|'  yourfile
>>
>> it will only change 3rd column.
>>
>>
>> On 26/11/12 20:26, Joel Hammer wrote:
>>> sed "s/\(\t\)\([0-9]\)/\1MY_\2/g"
>>>
>>> This seems to do what you want.
>>>
>>> Joel
>>>
>>>
>>>
>>> On Mon, 2012-11-26 at 15:05 +0100, MOKRANI Rachid wrote:
>>>>     
>>>> Hi,
>>>>
>>>> This is my firts port.
>>>>
>>>> I have a file with colum like this.
>>>>
>>>> Title1 Title2 Title3 Title4
>>>> AA B 66 D
>>>> BB DS 7 TT
>>>> VS FDSE 53 TGF
>>>> BG F 5 GF
>>>>
>>>> I would like to have with a sed command the following
>> result. Add the
>>>> character MY_ before all numbers in the colum number 3 and preserve
>>>> the
>>>> title "Title3". All the colums are seaprate by a tab.
>>>>
>>>> Title1 Title2 Title3 Title4
>>>> AA B MY_66 D
>>>> BB DS MY_7 TT
>>>> VS FDSE MY_53 TGF
>>>> BG F MY_5 GF
>>>>
>>>>
>>>>
>>>> Many thanks for your help/example.
>>>>
>>>> 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.
> __________________________
>
>
>
> ------------------------------------
>
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.