Help with Grep Function | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

Help with Grep Function

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-21-2009
msbaath msbaath is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 22 April 2009, 11:50 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Error Help with Grep Function

Okay, I am trying to grep a portion of a file that contains information like such:

1240257620:0134:149760:247777:6:111
1240257620:0134:149760:247777:0:110

1240257620:0105:149760:247774:1:110

1240257620:0134:149760:247774:0:110

1240257621:7309:152271:249738:1:110

1240257621:7309:152271:249738:0:110

1240257621:7308:152271:249738:0:110

1240257621:7309:152271:249738:0:110


I am interested in data that has :0???: in it.. ? could be any number
(eg:0134: or :0105:, etc.)
However, wild character does not work for some reason.. it greps nothing unless I try to grep specifically :0134: etc

I was wondering if it is possible to set character limit in the grep function (eg say grep anything between : & : that has 4 characters and the first one is "0" .. something like grep : len(4) & 1 character = 0 :

Let me know if I am not clear.

The file I am greping from is HUGE.. therefore I need to pull out info that has 4 characters in tnhe highlighted area starting with 0.

Thanks for your time and help
Sponsored Links
    #2  
Old 04-21-2009
dr.house dr.house is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 30 October 2011, 12:05 PM EDT
Location: Switzerland
Posts: 454
Thanks: 4
Thanked 27 Times in 27 Posts
Quote:
Originally Posted by msbaath View Post
I was wondering if it is possible to set character limit in the grep function (eg say grep anything between : & : that has 4 characters and the first one is "0" .. something like grep : len(4) & 1 character = 0 :

Code:
[house@freyja] echo "1240257620:0134:149760:247777:6:111" \
  | egrep -o ":0[0-9]{3}:" -
:0134:

Sponsored Links
    #3  
Old 04-21-2009
giannicello giannicello is offline
Registered User
 
Join Date: Sep 2001
Last Activity: 28 June 2014, 5:32 PM EDT
Location: Chicago
Posts: 190
Thanks: 7
Thanked 0 Times in 0 Posts
Or you can try sed...to see which is faster


Code:
sed '/:0[0-9]\{3\}:/!d' filename

or

Code:
sed -n '/:0[0-9]\{3\}:/p' filename

    #4  
Old 04-22-2009
msbaath msbaath is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 22 April 2009, 11:50 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
sed worked great! thank you guys!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else hariza Shell Programming and Scripting 4 09-18-2008 02:56 AM
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 11:39 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 02:59 AM
Function within function (Recurance) chassis UNIX for Dummies Questions & Answers 2 09-19-2006 09:32 AM
How to convert the "select" function into a "poll" function rbolante Programming 1 07-10-2001 10:49 AM



All times are GMT -4. The time now is 03:39 AM.