0

I am trying to print all words that are 3 chararcers long and those characters are from [a-s] interval. I have tried following

grep '\<[a-s]\{3\}\>' file.txt

which outputs nothing , i have also tried

grep '^[a-s]\{3\}$' file.txt

which also did nothing even when file containes just one word. (for ^ as start and $ as end of the line) How could i input words 3 char long from char interval / and how could i print words 3char long without interval?

  • That's the way to do it. If you want to print only the matching words, one per line, use grep -o. The best way to test it is to enter the command without a filename and type lines in directly. If you're examples don't work, then I would think that either, you didn't actually execute those commands or the patterns are not in file.txt, or something else is wrong with file.txt such as encoding. – RobertL Nov 20 '15 at 19:46
  • Have you alias grep? – Costas Nov 20 '15 at 20:26
  • You can check that it's not grep playing up by using sed: printf "%s\n" a bad boy rand over the bad boy ran | sed -n '/\<[a-s]\{3\}\>/p' – Max Murphy Nov 20 '15 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.