LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-30-2011, 10:46 AM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,135

Rep: Reputation: 299Reputation: 299Reputation: 299
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.
 
Old 11-30-2011, 10:55 AM   #2
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 43
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.

Last edited by ncsuapex; 11-30-2011 at 10:56 AM. Reason: .
 
Old 11-30-2011, 11:19 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Try egrep '^[a-z]{6}$'
 
1 members found this post helpful.
Old 11-30-2011, 01:14 PM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,135

Original Poster
Rep: Reputation: 299Reputation: 299Reputation: 299
Perfect! Thank you! Solved!
 
  


Reply

Tags
egrep


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
regex problem to find min,max length words in file gvanto Linux - Newbie 4 01-30-2011 05:34 PM
How to search for words in a song based on sound? lindylex Programming 6 10-07-2009 10:32 AM
Choosing DNS server based on domain being queried xtc Linux - Networking 3 10-01-2009 10:21 AM
Removing white spaces between words and joining the words in a given format Priyabio Linux - General 4 08-20-2009 07:42 AM
choosing hardware for linux based network mohtasham1983 Linux - Networking 2 04-17-2006 11:43 AM


All times are GMT -5. The time now is 03:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration