Take the 2-minute tour ×
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.

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

szientistischer
szientistisches
szintigraphische
szintigraphischem
szintigraphischen
szintigraphischer
szintigraphisches

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
2  
Are you sure the command did not work? I checked and the output was szintigraphische! –  coffeMug Oct 27 '13 at 11:55
1  
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
2  
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

1 Answer 1

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

Your Answer

 
discard

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.