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.

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'm, trying to use grep with a ^ and $ at the same time but for some reason that does not work. If I type

grep '^s.*e' german.dic

I get a lots of words starting with s and having an e somewhere. A snippet from the output


So there is a word 'szintigraphische', which has an e at the end of the line. What I would expect now is that if I typed

grep '^s.*e$' german.dic

that I would at least get that result. However, the resultset is empty. How should I write a correct regexp to find all words starting with an s and ending with an e?

share|improve this question
Are you sure the command did not work? I checked and the output was szintigraphische! – coffeMug Oct 27 '13 at 11:55
Ditto coffeMug. I literally cut n' pasted your snippet into a file, then cut and pasted your grep '^s.*e$' and it output 'szintigraphische' as it should. Maybe there is extra whitespace at the end of the line in file? – goldilocks Oct 27 '13 at 11:58
You can use this '^s.*e\s*$' to skip white spaces if there are any. \s* tells grep to ignore white spaces. – coffeMug Oct 27 '13 at 12:05
Yep, coffeMug, it was indeed whitespace ! Thanks for the help. – Werner Van Belle Oct 27 '13 at 12:13
@coffeMug - please write that up as an answer so it can be accepted and marked as resolved. – slm Oct 27 '13 at 14:35
up vote 3 down vote accepted

Perhaps you have some white spaces on the end of the 3rd line. To skip those you can modify your command as follows:

grep '^s.*e\s*$' german.dic 

\s* tells grep to include white spaces (tab/space/cr/lf) if there are any at the end of the current line.

share|improve this answer
Note that although \s is supported in grep (GNU grep 2.21 here), it's not documented, so using [[:space:]] would be safer. – Alois Mahdal Oct 10 '15 at 2:48

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.