I'm trying to grep username users |grep "^\b\w*\b" -P how to do it with grep?
Tell me more
×
Unix & Linux Stack Exchange is a question and answer site for
users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
|
If you really want return just the first word and want to do this with Yet, as @manatwork mentioned, shell built-in |
||||
|
|

grep?grepis for searching. You seem to need eithercutorawk, but thereadbuiltin also seems suitable. – manatwork Dec 7 '12 at 12:20users | cut -d' ' -f1,users | sed 's/\s.*//',users | awk '$0=$1'. If you want to store it in a variable, usingbash:read myVar blah < <(users)orread myVar blah <<< $(users). – manatwork Dec 7 '12 at 13:33readyou don't spawn a new process. If you do this many times, you'll notice the difference. – peterph Dec 7 '12 at 15:19