file.txt contains:
##w##
##wew##
using mac 10.6, bash shell, the command:
cat file.txt | grep [[:alpha:]]* -o
outputs nothing. I’m trying to extract the text inside the hash signs. What am i doing wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
(Note that it is better practice in this instance to pass the filename as an argument to grep instead of piping the output of cat to grep:
grep PATTERN fileinstead ofcat file | grep PATTERN.)What shell are you using to execute this command? I suspect that your problem is that the shell is interpreting the asterisk as a wildcard and trying to glob files.
Try quoting your pattern, e.g.
grep '[[:alpha:]]*' -o file.txt.I’ve noticed that this works fine with the version of grep that’s on my Linux machine, but the grep on my Mac requires the command
grep -E '[[:alpha:]]+' -o file.txt.