The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find lines with space between strings Galt Shell Programming and Scripting 5 05-07-2008 02:06 PM
grep: outputting search strings tapmas Shell Programming and Scripting 3 03-10-2008 04:58 AM
Find information from complicated strings lalelle Shell Programming and Scripting 9 02-12-2008 11:28 AM
To find multiple strings count in a file salaathi Linux 3 11-28-2007 06:31 AM
how to use GREP comaand to search strings in This OR That scenrio vj_76 UNIX for Dummies Questions & Answers 4 07-26-2005 10:17 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-02-2003
crabtruck crabtruck is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 3
Question Using grep to find strings of certain lengths?

I am trying to use grep to find strings of certain lengths that all start with the same letter. Is this possible?
  #2 (permalink)  
Old 11-03-2003
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
If your grep has the -w option,
Code:
grep -w 's...' file
  #3 (permalink)  
Old 11-03-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
You could use awk, unless you're impartial to grep for some reason:

awk '$0~"^s" && length($0)==12' yourFile

In the example, you're searching for lines starting with the letter "s" with a length of 12.
  #4 (permalink)  
Old 11-04-2003
Simerian Simerian is offline
Registered User
  
 

Join Date: Oct 2003
Location: United Kingdom
Posts: 37
egrep will also work with a regexp that matches a specific length (i.e. [A-Za-z]{12,12})
  #5 (permalink)  
Old 11-04-2003
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
To Simerians point, his regexp accounts for files that start with both upper case and lower case letters. Adding the switch "-i" to the other grep examples will allow you to ignore case.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0