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.
You need to anchor the string you're searching for. Try
egrep '^avi:' /etc/passwd.
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.
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