Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove nth character from a string variable in Linux bash shellscript

I have seen many methods for removing some characters based on regular string or special match using tr etc. But I didn’t find any way to delete a character based on accurate index in a string.

For example: In var="hello world",I want to delete the 5th char ‘o’ and then var should be like "hell world". The code should apply to all other normal strings. Thanks in advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

One method is:

n=5
var="hello world"
var=${var:0:n-1}${var:n}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading