Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
Hi All,
I am a newbie and not sure if this is the right fourm to ask.
II just have an string "builder_test_string1ABC001_test" and I would like to extract ABC001 from this. Please note that 001 is dynamic and it can change to any numerical value. I wanted to do this in a shell script.
What is the pattern of the bits you want to keep or destroy? Do you always want three capital letters followed by three numbers? Are they always the only capital letters? Is it always the last six characters you want? Do you always want the substring beginning ABC and finishing at the next underscore? We'd need more sample data to offer any specific help, and we'd *really* like to see what you've tried so far, or even just how you intend to approach this.
You'll likely want to look at sed, awk, and regular expressions. There are a couple of bash scripting guides on www.tldp.org which are mostly invaluable if you've any bash script writing to do.
There is also "grep -o" which returns only the matched expression (but only once per line).
In constructing the regular expression, we also need to know if "any numerical value" means any number of digits---i.e. do you need to match "ABC34", ABC289057", etc.
Hi thanks for ur reply. Actually the mentioned string is an output of an clearcase command. I am writing a automatic script which creates a directory called "ABCxxx". All other data in the string is static and will not change. And also this ABC can be in small case also. I always wanted the substring starting from ABC and finishing at the next underscore.
Ex:
String: builder_project1_projectabc023_build
And I always wanted to keep abc023
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.