Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
OK, if you just want to return the word chrome, that's pointless. You know it's chrome, why extract it? What I was getting at is what you want to do in general terms. E.g. is it that you are dealing with urls of this type that may have various values for sourceid in them and you want to get that value? If so then these methods both work
I want grep to return the word "chrome" to stdout.
The only option in the grep man page that approaches what you want is:
Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
So, in theory, yes you could, but your regex won't be able to work the way you want. There is no text inside the word "chrome" to differentiate it from any other text. If you try to pull in "sourceid", then grep's output will include "sourceid"--which is not what you want.
The back references won't help you because, if you can back reference something, that means it matched in the regular expression. If it matched in the regular expression, then grep will print it. Therefore, the only back reference you can use would be to reference the match itself. If you're back referencing the match, you don't need the back reference to begin with.
I think the tool you are really looking for is sed--as demonstrated by sycamorex.
Given the sample data above, the only thing I can think of would be: