[SOLVED] [BASH][SED] Find pattern and replace it's [pattern's] last character
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
st="blablalb A i B. E. lalalalal.
A. tralala,la A B i C.
B. elellfdew A. fww.
C. DiDweofjoie zalamki T."
sed 's/\,/\./g' <<< "$st"
blablalb A i B. E. lalalalal.
A. tralala.la A B i C.
B. elellfdew A. fww.
C. DiDweofjoie zalamki T.
Or did I miss something.
Edit:You hightlighted/changed it while I was answering.
Hi guys, thank you for your replies.
@teckk - sorry about that. I thought it would be useful to highlight patterns as its a tricky one.
@boughtonp - I tried to use my pattern " i [A-Z][.]" but that doesnt work. Thanks anyway for reply
Note: this is to replace . with , ONLY when dot stands next to capital letter followed by " i " (mind the spaces)
eg.
that is still not ok.
But first: you cannot use a regexp in the right side (replacement string), because there is no string to match. You need to specify the replacement string itself.
If you want to specify dot (.) you must use [.] (or \.), not (.) as regexp, and you need not use \ in the replacement string before the comma (but \1 is ok, because it has a special meaning).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.