Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2006 01:55 AM
тАО03-23-2006 01:55 AM
grep
i did /etc/passwd | grep
Now, that username was there, but the output that i got was /etc/passwd[14]: mysql:*:102:102::/home/mysql:/sbin/sh: not found. And the list went on like this.
Now, to my understanding, u put in a file name and then concatenate it with grep to find a particular string in that file or what ever is it that u r lookig it in.
So, how come the grep is giving me alist of all the usernames when all i am grepping is a particular and unique username.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2006 01:59 AM
тАО03-23-2006 01:59 AM
Re: grep
Try grep username /etc/passwd
You might get better results. You'll certainly get them more efficiently.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2006 02:06 AM
тАО03-23-2006 02:06 AM
Re: grep
You should rather use,
# grep -i mysql /etc/passwd
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2006 02:13 AM
тАО03-23-2006 02:13 AM
Re: grep
as a second option :
You may have missed out "cat " in front of the /etc/passwd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2006 02:17 AM
тАО03-23-2006 02:17 AM
Re: grep
# /etc/passwd | grep
Then no, that will not work. Your example would try to execute the /etc/passwd file, which would not work and would error on each and every line. You got all lines, because 1) they are not valid shell script commands and 2) grep works on 'standard out' file descriptor and everything you saw was going to 'standard error' file descriptor.
You must cat the file and pipe to grep:
# cat /etc/passwd | grep
or you can just use the grep command and specify the file name you are querying at the end of the command, as previous post suggested.
# grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2006 02:18 AM
тАО03-23-2006 02:18 AM
Re: grep
Hmm... the unix world as we know it would come to a grinding hold if grep was as badly broken as you suggest.
>> i did /etc/passwd | grep
Ah.... you missed a 'cat ' in front of that, or just use the preferred 'grep
>> output that i got was /etc/passwd[14]: mysql:*:102:102::/home/mysql:/sbin/sh: not found. And the list went on like this.
Seems to me you are actually EXECUTING passwd as a script and indeed 'mysql' would be a command which is not found.
What is the MODE on /etc/passwd
You should not have an x (execute) bit there.
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2006 02:22 AM
тАО03-23-2006 02:22 AM
Re: grep
If you are going to 'grep' usernames in '/etc/passwd' I suggest that you do something like:
# grep "^tftp:" /etc/passwd
That is, the caret (^) anchors the search to the beginning of the line. The colon (:) matches the string at the '/etc/passwd's first field end. This will give much more accurate matching and eliminate spurious matching.
Do *not* spawn a new, unnecessary process by doing :
# cat /etc/passwd | grep ...
That is needless and wasteful. 'grep' takes its input from STDIN or the filename supplied as its last argument.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2006 04:54 AM
тАО03-23-2006 04:54 AM
Re: grep
mysql:*:102:102::/home/mysql:/sbin/sh
# cat /etc/passwd | grep mysql
mysql:*:102:102::/home/mysql:/sbin/sh
Now, y first the grep was before the /etc/passwd and in the other case after it. Yet giving the same output.
Do u huys ever use egrep or fgrep on a regular basis.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2006 05:01 AM
тАО03-23-2006 05:01 AM
Re: grep
If you use the '-E' and '-F' switches with 'grep' you get the functionalty of 'egrep' and 'fgrep' respectively.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-23-2006 06:05 AM
тАО03-23-2006 06:05 AM
Re: grep
>> Now, y first the grep was before the /etc/passwd and in the other case after it. Yet giving the same output.
That's very basic Unix shell behaviour.
The syntax for grep and many other commands (zip, head, wc,...) is:
command
If no filename for
In the second case, you did not give am explicit filespace to grep, so it read STDIN which got it's data piped in from the preceding pipe command.
Clear as mud?
Hein.