LookIntoEast
LookIntoEast

Reputation: 8798

Remove trailing letters at the end of string

I have some strings like below:

ffffffffcfdeee^dddcdeffffffffdddcecffffc^cbcb^cb`cdaba`eeeeeefeba[NNZZcccYccaccBBBBBBBBBBBBBBBBBBBBBB

eedeedffcc^bb^bccccbadddba^cc^e`eeedddda`deca_^^\```a```^b^`I^aa^bb^`_b\a^b```Y_\`b^`aba`cM[SS\ZY^BBB

Each string may (or may not) end with a stretch of trailing B of varied length. I'm just wondering if we can simply use Bash code to remove the B stretch?

Upvotes: 1

Views: 4034

Answers (3)

glenn jackman
glenn jackman

Reputation: 246774

just with bash

shopt -s extglob
str="a.zxn;lqwyerpyqgha;lsdnBBBBB"
str=${str%%+(B)}
echo $str   # ==> a.zxn;lqwyerpyqgha;lsdn

Upvotes: 3

potong
potong

Reputation: 58371

This might work for you:

sed 's/B*$//' file

Upvotes: 0

user353608
user353608

Reputation:

You could try something like

sed 's/\(.\)B*$/\1/' file

Input

aaa BBBBB
aaa BBBBB cccc
aaa bbb ccc BBBBBBB

Output

aaa
aaa BBBBB cccc
aaa bbb ccc

Upvotes: 3

Related Questions