LKBEN11691: How to eliminate grep in the output of grep itself.
Symptom
You need to find some process but you always find at least one result because of grep.
Cause
This is by design.
Solution
If you need to find some process with grep, you will always find the the grep result itself. To eliminate this line, you can use the -v parameter which stands for invert-match.
An example: you need to find out if sshd is running on a system. To search for sshd, you use the following command:
ps -ef|grep sshd
root 1602 1 0 13:28 ? 00:00:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
wpeeters 44755 5975 0 13:43 pts/1 00:00:00 grep --color=auto sshd
You notice the line with grep! This is the grep command itself, used to find the sshd. To eliminate this line, you can use one more grep command and invert the search.
ps -ef|grep sshd|grep -v "grep"
root 1602 1 0 13:28 ? 00:00:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
This eliminated the line with grep.
Have fun.
Disclaimer:
The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!About the Author
Author:
- Keskon GmbH & Co. KGWim Peeters is electronics engineer with an additional master in IT and over 30 years of experience, including time spent in support, development, consulting, training and database administration. Wim has worked with SQL Server since version 6.5. He has developed in C/C++, Java and C# on Windows and Linux. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform.
Latest update: 23-11-2023