LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Choosing words based on length (https://www.linuxquestions.org/questions/linux-newbie-8/choosing-words-based-on-length-916394/)

danielbmartin 11-30-2011 10:46 AM

Choosing words based on length
 
I have a large file containing text, one word per line. I want to keep only those lines in which the word length is a specific number of lower-case characters.

Suppose the desired length is 6.
I tried this: egrep [a-z]{6} but it didn't do the job.

Please advise.

ncsuapex 11-30-2011 10:55 AM

cat filename |cut -c 1-6 >> filename2


You can change the redirection to fit your needs.


Although that only cuts the first 6 characters of each line. You'll need to look at sed to pick out just the lines containing exactly 6 characters.

catkin 11-30-2011 11:19 AM

Try egrep '^[a-z]{6}$'

danielbmartin 11-30-2011 01:14 PM

Perfect! Thank you! Solved!


All times are GMT -5. The time now is 06:58 AM.