MOKRANI Rachid rachid.mokrani@ifpen.fr [sed-users]
2016-11-10 14:03:10 UTC
Hi, (It's been a long time)
I have some files.
cat A.txt
Paul Brown
monday
0.8
Mike Blue
monday
0.8
Tom Red
friday
0.8
Virginie Rose
saturday
0.8
David Brown
saturday
0.7
Brian Yellow
monday
0.55
Tom Black
thuesday
0.4
cat B.txt
Bill White
thusday
0.8
Manu Purple
monday
0.8
William Grey
thuesday
0.7
Nathalie Golden
monday
0.8
Marie Pink
sunday
0.6
Susan Navy
sunday
0.6
I want to search in this files the string "Tom Red" and change ONLY the 3 third lines after the result. In this example the string is in the file "A.txt" and need to change "0.8" by "MY_NEW_STRING"
grep -A 3 "Tom Red" *.txt (it's OK)
But How to replace ONLY the third string after ""Tom Red" ?
The result should be.
cat A.txt
Paul Brown
monday
0.8
Mike Blue
monday
0.8
Tom Red
friday
MY_NEW_STRING
Virginie Rose
saturday
0.8
David Brown
saturday
0.7
Brian Yellow
monday
0.55
Tom Black
thuesday
0.4
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]
I have some files.
cat A.txt
Paul Brown
monday
0.8
Mike Blue
monday
0.8
Tom Red
friday
0.8
Virginie Rose
saturday
0.8
David Brown
saturday
0.7
Brian Yellow
monday
0.55
Tom Black
thuesday
0.4
cat B.txt
Bill White
thusday
0.8
Manu Purple
monday
0.8
William Grey
thuesday
0.7
Nathalie Golden
monday
0.8
Marie Pink
sunday
0.6
Susan Navy
sunday
0.6
I want to search in this files the string "Tom Red" and change ONLY the 3 third lines after the result. In this example the string is in the file "A.txt" and need to change "0.8" by "MY_NEW_STRING"
grep -A 3 "Tom Red" *.txt (it's OK)
But How to replace ONLY the third string after ""Tom Red" ?
The result should be.
cat A.txt
Paul Brown
monday
0.8
Mike Blue
monday
0.8
Tom Red
friday
MY_NEW_STRING
Virginie Rose
saturday
0.8
David Brown
saturday
0.7
Brian Yellow
monday
0.55
Tom Black
thuesday
0.4
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]