Reputation: 4328
I have a file say Abc.txt . It consist of many lines. I want to use sed or may be any other command that modifies that line in place in that file. Suppose line has just one word like below
ABCDsdfg01klmn
Here I check if line starts with ABC and then check if it also has 00 and in that case I want to modify 01 by say PM . How can i do it ?
I want to add some further specific . I want it to be done only for lines that have say 4 character between ABCD and 01 . I dont want to modify it for lines say that has 3 characters or 5 characters between ABCD and 01 e.g ABCDsfg01klmn
or ABCDsdfgh01klmn
ABCDsdfgPMklmn
Upvotes: 0
Views: 34
Reputation: 158020
With sed
:
sed -r 's/^(ABCD.{4})01/\1PM/' file
If a line contains ABC
plus 4 characters and a 01 the s
command is used to replace 01
by PM
.
Upvotes: 3