sed - need to replace only the chars or symbol after 1st and 2nd dot(.) with "int1" and "int2" respectively.
Here is what I have tried but it replaces the strings in other lines.

End result should look like - A.int1.int2.any.string.here

sed -e 's//int1/' -e 's//int2/' -e 's/ABCD/int1/' filename

A...ABCD.DEFG.HIJK
A..ABCD.EFGH.IJKL
A.ABCD.
EFGH.JKLM

sed uses the 's///' command to replace one string with another. You need to choose the string to be replaced and put it in the first space between the first two forward slashes and put the new string between the second two.

In this case, knowing regular expressions will help. Test with the folowing:

echo "A...ABCD.DEFG.HIJK" | sed -e 's/\([A-Z]\)\./\1\.int1\./' -e 's/\.\./\.int2/'

The output is:

A.int1.int2.ABCD.DEFG.HIJK

It might be easier if you choose a different character to divide up the sections of the replacement command for sed:

echo "A...ABCD.DEFG.HIJK" | sed -e 's_\([A-Z]\)\._\1\.int1\._' -e 's_\.\._\.int2_'

That way you can see which items are being removed and which are being added in.

I know that the above code is a little cumbersome. I am a great believer in elegance in simplicity. However, I am still learning, and this is what I know at this point. I welcome corrections toward simplicity.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.