LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-04-2021, 05:35 PM   #1
dr.x
Member
 
Registered: Jan 2013
Posts: 231

Rep: Reputation: Disabled
How to match exact sting in linux and avoid many possibilities


Hello Folks ,

If I use :

ps aux | grep X

it will match all services including X and match too like X1 , X12 , X13 , X14

My question is how only match X and nothing more ? like exclude the other possibilities ?


Thanks
 
Old 07-04-2021, 06:25 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,152

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
Start by reading the manpage. If "-o" isn't sufficient, you'll have to get to know regex - word bounding anchors would be handy. And by co-incidence they are mentioned in the manpage.
 
1 members found this post helpful.
Old 07-04-2021, 06:31 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by dr.x View Post
Hello Folks ,

If I use :
ps aux | grep X

it will match all services including X and match too like X1 , X12 , X13 , X14 My question is how only match X and nothing more ? like exclude the other possibilities ?
Seems to be a recurring thing:
https://www.linuxquestions.org/quest...ng-4175695075/
https://www.linuxquestions.org/quest...er-4175694196/

As with several of your previous threads, you've not shown any effort of your own, despite having similar threads (with solutions) to draw on. Show us what you have done/tried on your own first, do basic research, and read the documentation.
 
1 members found this post helpful.
Old 07-04-2021, 08:05 PM   #4
GentleThotSeaMonkey
Member
 
Registered: Dec 2016
Posts: 338
Blog Entries: 4

Rep: Reputation: 128Reputation: 128
+1 #3 (-1 #2 -o )

I would be embarrassed to ask, IF I hadn't first:
web-searched: grep match only exact word
(hint: switch underlined)

Web-search: .pdf linux book
will find lots of books you could study.
 
Old 07-05-2021, 02:46 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
not to speak about pgrep. You need to use pgrep instead of ps ... | grep ...
 
1 members found this post helpful.
Old 07-05-2021, 09:28 AM   #6
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,167

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Not tested:

ps aux | grep '^X'

ps aux | grep '^X{3}'

or pgrep '^X'
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to capture 1000 lines before a string match and 1000 line a string match including line of string match ? sysmicuser Linux - Newbie 12 11-14-2017 05:21 AM
[SOLVED] Finding the Big and Exact Match of Sample Data hamijami Programming 20 05-31-2012 02:07 AM
[SOLVED] Match datetime by the minute (not an exact match by the second) [mysql] hattori.hanzo Programming 1 10-21-2010 05:43 PM
LXer: Linux on Zune creates many possibilities LXer Syndicated Linux News 0 12-29-2006 05:54 PM
Mandrake 9.1 -- No Internet -- Many possibilities bran noob Linux - Newbie 12 03-08-2004 10:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration