[SOLVED] limit result of a grep command using the w switch
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.
I guess I'm getting the app11 output b/c of the ".app1."(bolded) above. Can anybody think of a way for me to only get "app1" as the result?
I know there are several ways to get what I'm looking for if this was case specific, ie "grep ' app1$' but don't want that, I am using this in a script so don't want it to be a case specific. And using field delimiters is also not an option bc the script actually is trying to determine which host the app1 process runs(prod05).
I guess I'm getting the app11 output b/c of the ".app1."(bolded) above. Can anybody think of a way for me to only get "app1" as the result?
I know there are several ways to get what I'm looking for if this was case specific, ie "grep ' app1$' but don't want that, I am using this in a script so don't want it to be a case specific. And using field delimiters is also not an option bc the script actually is trying to determine which host the app1 process runs(prod05).
Thx.
Hi scripter,
what's wrong with using "grep -w app1$"? The $ just stands for end-of-line, and it shouldn't make anything case-specific that isn't already case-specific in your original command. You can use -i ("grep -wi app1$") to really ignore cases either way.
-nevermind-
You can use a regular expression ".*app1[^1]*"
.* = any character
app1 = app1
[^1] = not 1 (after app1)
The options for grep -ow. o is print only the matching part of the regex (".*app1[^1]*") and w is whole words.
Sorry guys, these don't work b/c there's also an invisible character(^M) at the end of the line so using reg expersions is not an option. I can remove them for now but what happens later when someone else udates the file with (copy and paste mostly) with another invisible character for a different process name. I want the script to be general general solution not a specific case solution. how do i get grep to not return a result for the ".app1." match. That's where the issue is
Sorry guys, these don't work b/c there's also an invisible character(^M) at the end of the line so using reg expersions is not an option. I can remove them for now but what happens later when someone else udates the file with (copy and paste mostly) with another invisible character for a different process name. I want the script to be general general solution not a specific case solution. how do i get grep to not return a result for the ".app1." match. That's where the issue is
Hey scripter,
I see where you're heading, but what exactly are the requirements? What invisible characters do you need to exclude, precisely?
If you want to allow any set of white space between "app1" and the end of the line, you can use this:
egrep -wi "app1[[:space:]]*$"
... which matches all lines ending with app1 followed by an arbitrary set of white-space characters.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.