How do you grep a character only?

Say I want to print only character. How do you grep a character only and then store that into a shell variable?

grep search pattern for single character:

  • . : Any single character
  • [...] : Any single character in the bracketed list or range
    So to grep a character only, you will do:
grep '.' filename

To match only one character:

grep -w '.' filename
result=$(grep -w '.' filename)
echo "$result"

thank you. I did it as

grep -w '[[:alpha:]]' data005.file
grep -w '[[:alnum:]]' data006.file 

it took me while but it is now working.

Check our grep and egrep pages:

And:


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki