0

I want help to print only one name from my /etc/passwd file. For example, if there are two entries named "avi" and "avig", then how should I print only "avi"? I have tried cut, unique command but am not getting proper output.

6

You need to anchor the string you're searching for. Try egrep '^avi:' /etc/passwd.

6

If you want to get just the entry for a given user from your passwd you should just use the getent command like

getent passwd avi

otherwise, you'll just need to make sure your regex/pattern is specific enough to only match what you want.

If your grep supports it you can tell grep to only match your pattern as the whole word like

grep -w ^avi /etc/passwd

works with GNU and BSD greps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.