Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a lab question asking me to use grep with a regex pattern to match every word where the third letter from the beginning of the line is an "a" and save it with a redirect. How can I do that?

share|improve this question

This should answer your question:

grep -e "^..a" < input > savefile
share|improve this answer
Nice and simple solution. I don't think -e is even needed here - like grep ^..a < input > output should suffice. – user13742 Feb 20 '12 at 16:34

The solution proposed by @rahmu is simple if you look for low positions, but what if you look for the character number 25? Put in 25 dots?

In such a case the following solutions could be at hand. With grep

grep '^.\{24\}a' input >output

With awk

awk -F '' '$25 == "a"' input >output
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.