6

I want to delete the occurrence of a character in a string only for the first occurrence.

Example:

echo "B123_BACK" | tr -d 'B'

This results in output:

123_ACK

How can I delete only the first occurrence of charcater 'B' so that the output looks like

123_BACK
g4ur4v
  • 1,764
  • 8
  • 29
  • 34

1 Answers1

15

Looking at the tr man page, this isn't possible. Why not use sed instead:

echo "B123_BACK"|sed 's/B//'
Joseph R.
  • 39,549