Q:

Need to delete all data after third colon of a string

i have a file say test.txt with the following contents
apple:orange:mango:123:1234:12345

i want all data after third colon to be removed 
Expected output
apple:orange:mango:

Kinldy help

A:

Using backreference:
sed 's/\([^:]*:[^:]*:[^:]*:\).*/\1/' test.txt

or with GNU sed:
sed -E 's/(([^:]*:){3}).*/\1/' test.txt

