grepping for an expression, not listing the whole line
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!
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.
grepping for an expression, not listing the whole line
How do I grep, or using awk or sed, a file to find and list and expression part of which stays the same and part of which changes. Also, I would like to not have the whole line listed, just the words found?
for example, in the file are many different instances of 'ABC=123456.' ABC stays the same, but 123456 chasnges, both in the number of integers and the integers themselves. And, when I display the results of the grep, I would like it to display each line with ABC=123456 only, not the whole line. If I use grep -o ABC=, I just get ABC=.
grep alone probably won't do that.
grep for the lines you want, e.g. "grep ABC= file"
then pipe into a sed command to replace what you don't want with nothing, i.e. "s/ABC=//"
Cheers, Tom.
Here is an example. There are many lines like the one below in the log file. I have made many substitutions in the example below because it is proprietary information.ABC=XXXXXXXX is all that I want from the lines. ABC is a constant; those aren't the letters but there are three letters that stay the same.What ABC equals in each line is different in each line (it is not XXXXs). And the rest of the information in this line is even more than what is in this example, and it varies from line to line.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.