Shell script to edit fields in a file

Solved/Closed
Estanislau Posts 3 Registration date Saturday February 12, 2011 Status Member Last seen February 17, 2011 - Feb 12, 2011 at 10:35 AM
zipe31 Posts 36402 Registration date Sunday November 7, 2010 Status Contributor Last seen January 27, 2021 - Feb 17, 2011 at 11:50 AM
Hello,
I have a big file in wich I would like to rename inside exactly the string '_ME' and not rename in case we have 'ABC_MELANGE'. Is there a way to do it by using a shell script?
Please help me. Any tip will be apreciated.

The file is like described bellow:

toto test@GR_4||4_35_1_ME||4_35_17
DntowoB.nts
toto test@DT_3||4_35_1_ME||4_35_17
DntsGoF.nts
toto test@FAIFAI11-O8M5_south_e9000/A18_06_MEmCentralNW_PAB/07
DnBs0I2.nts
toto test@FAIFAITulipa-M6C-1010/A18_06_MEmCentral_PAB/07
Dot50nD.nts
toto test@GR_2||4_55_1_ME||4_55_17
Dp2GzpT.nts
toto test@DT_2||4_55_1_ME||4_55_17
Dp2JIpX.nts
toto test@RDEEP_2||ABC_MELANGE-3B_ME||ABC_MELANGE-3B_Leg17
Dr1aFqf.nts
toto test@NPHI_2||ABC_MELANGE-3B_ME||ABC_MELANGE-3B_Leg17
Dr1e7qj.nts
toto test@GR_2||ABC_MELANGE-3B_ME||ABC_MELANGE-3B_Leg17
Dr1hBqn.nts
toto test@DT_2||ABC_MELANGE-3B_ME||ABC_MELANGE-3B_Leg17
Dr1lUqr.nts
toto test@RHOB_3||ABC_MELANGE-3B_ME||ABC_MELANGE-3B_Leg17
Dr1pEqv.nts


Thanks
Related:

2 responses

zipe31 Posts 36402 Registration date Sunday November 7, 2010 Status Contributor Last seen January 27, 2021 2
Feb 16, 2011 at 01:24 PM
Hello,

$ cat plop
toto test@GR_4||4_35_1_ME||4_35_17
DntowoB.nts
toto test@DT_3||4_35_1_ME||4_35_17
DntsGoF.nts
toto test@FAIFAI11-O8M5_south_e9000/A18_06_MEmCentralNW_PAB/07
DnBs0I2.nts
toto test@FAIFAITulipa-M6C-1010/A18_06_MEmCentral_PAB/07
Dot50nD.nts
toto test@GR_2||4_55_1_ME||4_55_17
Dp2GzpT.nts
toto test@DT_2||4_55_1_ME||4_55_17
Dp2JIpX.nts
toto test@RDEEP_2||ABC_MELANGE-3B_ME||ABC_MELANGE-3B_Leg17
Dr1aFqf.nts
toto test@NPHI_2||ABC_MELANGE-3B_ME||ABC_MELANGE-3B_Leg17
Dr1e7qj.nts
toto test@GR_2||ABC_MELANGE-3B_ME||ABC_MELANGE-3B_Leg17
Dr1hBqn.nts
toto test@DT_2||ABC_MELANGE-3B_ME||ABC_MELANGE-3B_Leg17
Dr1lUqr.nts
toto test@RHOB_3||ABC_MELANGE-3B_ME||ABC_MELANGE-3B_Leg17
Dr1pEqv.nts

$ sed -i.bak 's/_ME\b/NEW_STRING/g' plop

$ cat plop
toto test@GR_4||4_35_1NEW_STRING||4_35_17
DntowoB.nts
toto test@DT_3||4_35_1NEW_STRING||4_35_17
DntsGoF.nts
toto test@FAIFAI11-O8M5_south_e9000/A18_06_MEmCentralNW_PAB/07
DnBs0I2.nts
toto test@FAIFAITulipa-M6C-1010/A18_06_MEmCentral_PAB/07
Dot50nD.nts
toto test@GR_2||4_55_1NEW_STRING||4_55_17
Dp2GzpT.nts
toto test@DT_2||4_55_1NEW_STRING||4_55_17
Dp2JIpX.nts
toto test@RDEEP_2||ABC_MELANGE-3BNEW_STRING||ABC_MELANGE-3B_Leg17
Dr1aFqf.nts
toto test@NPHI_2||ABC_MELANGE-3BNEW_STRING||ABC_MELANGE-3B_Leg17
Dr1e7qj.nts
toto test@GR_2||ABC_MELANGE-3BNEW_STRING||ABC_MELANGE-3B_Leg17
Dr1hBqn.nts
toto test@DT_2||ABC_MELANGE-3BNEW_STRING||ABC_MELANGE-3B_Leg17
Dr1lUqr.nts
toto test@RHOB_3||ABC_MELANGE-3BNEW_STRING||ABC_MELANGE-3B_Leg17
Dr1pEqv.nts
$

;-))
2
Estanislau Posts 3 Registration date Saturday February 12, 2011 Status Member Last seen February 17, 2011
Feb 17, 2011 at 02:08 AM
Hi Zipe31,
thank you very much for your answer. That's great it works perfectly.

Regards
0
zipe31 Posts 36402 Registration date Sunday November 7, 2010 Status Contributor Last seen January 27, 2021 2
Feb 17, 2011 at 11:50 AM
You're welcome ;-)
0