Search code examples
linuxstringbashcut

Cut characters from position from string in bash


I have the following string, which it will always be 35 characters long:

S202SCTRXBAVCWPJAC001181204120000.N

I would like to cut 3 characters (position 17-19), JAC in this case, to remain only

S202SCTRXBAVCWP001181204120000.N

Is there a way to achieve this in bash?


Solution

  • Agree with the answer by Charles Duffy. If you know you want specifically "JAC" instead of what indices you want removed, you could do:

    str="S202SCTRXBAVCWPJAC001181204120000.N"
    echo "${str/JAC/}"