hurnhu hurnhu - 3 months ago 8
Linux Question

how to use grep to search for a word beginning with...

okay im what im trying to do is use grep to look through a file, and find words starting with the lowercase letter s. for the life of my i cant get it. example of stuff in file.

sjpope pts/2 161.133.12.95 10:21am 43.00s 0.13s 0.01s man bc
rmschalk pts/3 161.133.9.147 10:22am 1.00s 0.10s 0.02s vi testb
jntrudel pts/4 161.133.9.11 10:23am 2.00s 0.09s 0.00s vi testb
tjbanks pts/5 161.133.9.70 10:41am 8.00s 0.06s 0.04s -ksh


and i want the output to only show the one starting with the s

kai kai
Answer

Have you tried using a regular expression? The ^ character will search from the beginning of the string. In your particular case, for example, if you want all results that start with a lowercase 's':

    cat file | grep ^s

or simply

grep ^s file
Comments