The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
GREP and Retrieve Line by Line maxmave Shell Programming and Scripting 2 06-03-2008 12:45 PM
How to grep only 1st line St.Fartatric UNIX for Dummies Questions & Answers 3 05-19-2008 07:24 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 03:59 AM
grep the line only if next line matches pbsrinivas Shell Programming and Scripting 11 07-10-2007 09:51 AM
diffrent results between command line and scripted grep r1500 Shell Programming and Scripting 1 11-24-2003 02:05 PM

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 12-15-2005
PradeepRed PradeepRed is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 25
Grep using line command

Hello

I have a pretty big problem here. I have a very large file having lines running into millions. A small sample of the data is shown below

<CRMSUB:MSIN=5000000013,BSNBC=TELEPHON-55108663-TS11&TS21&TS22,MSCAT=ORDINSUB,SUBRES=ALLPLMN-AIRSIMLA,BAOC=OIC,NUMTYP=MULTI;
<ENTRGCSERV:MSIN=5000000013,GCSERV=CALLWAIT-PROV&CALLHOLD&CLIP,CLIPOVR=NO;
<ENTRCBSERV:MSIN=5000000013,CBSERV=CBOIC,BSVG=TELEPHON,CCB=OPR,PW=0000;
<ENTRCFSERV:MSIN=5000000013,CFSERV=CFBUSY,NCS=NO,NFS=NO;
<ENTRCFSERV:MSIN=5000000013,CFSERV=CFNREPLY,NCS=NO,NFS=NO;
<ENTRCFSERV:MSIN=5000000013,CFSERV=CFNREACH,NCS=NO;
<ENTRCFSERV:MSIN=5000000013,CFSERV=CFU,NCS=NO;
<CRMSUB:MSIN=5000000017,BSNBC=TELEPHON-55103911-TS11&TS21&TS22,MSCAT=ORDINSUB,SUBRES=ALLPLMN-AIRSIMLA,BAOC=OIC,NUMTYP=MULTI;
<ENTRGCSERV:MSIN=5000000017,GCSERV=CALLWAIT-ACT-TELEPHON&CALLHOLD&CLIP&NATSS05,CLIPOVR=NO;
<ENTRCBSERV:MSIN=5000000017,CBSERV=CBOIC,BSVG=TELEPHON,CCB=OPR,PW=0000;
<ENTRCFSERV:MSIN=5000000017,CFSERV=CFBUSY,NCS=NO,NFS=NO;
<ENTRCFSERV:MSIN=5000000017,CFSERV=CFNREPLY,NCS=NO,NFS=NO;
<ENTRCFSERV:MSIN=5000000017,CFSERV=CFNREACH,NCS=NO;
<ENTRCFSERV:MSIN=5000000017,CFSERV=CFU,NCS=NO;
<CRMSUB:MSIN=5000000019,BSNBC=TELEPHON-55169401-TS11&TS21&TS22,MSCAT=ORDINSUB,SUBRES=ALLPLMN-AIRSIMLA,BAOC=OIC,NUMTYP=MULTI;
<ENTRCFSERV:MSIN=5000000019,CFSERV=CFBUSY,NCS=NO,NFS=NO;
<ENTRCFSERV:MSIN=5000000019,CFSERV=CFNREPLY,NCS=NO,NFS=NO;
<ENTRCFSERV:MSIN=5000000019,CFSERV=CFNREACH,NCS=NO;
<ENTRCFSERV:MSIN=5000000019,CFSERV=CFU,NCS=NO;
<ENTRGCSERV:MSIN=5000000019,GCSERV=CALLWAIT-PROV&CALLHOLD&CLIP,CLIPOVR=NO;

As can be seen there is only common parameter ie the MSIN. Now i have to obtain data for close to a 1000 different MSINs. I cannot grep for those MSINs from my entire data. If the first occurence for a particular MSIN is say on line 4000 of 1000000 lines. If i know that the MSIN will occur from lines 4000 to 4020 and guaranteed that the MSIN will not occur after line 4020, then is there a way that my grep command will exit after line 4020 and start looking for the next MSIN?

Will be very grateful if anyone can suggest a quick and easy solution for this.

Thanks in advance

Regards
Pradeep
  #2 (permalink)  
Old 12-15-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
Put all 1000 strings to find in a file called targets. Then do:
grep -Ff targets /big/data/file
That's about the best you can do quickly. It will be just one pass through the big file. I'm not sure if grep can handle 1000 strings, this could be the only problem. Use the -F as I show, it is faster since no regular expressions are involved. Do a practice run with small files to be sure you have the syntax right.
  #3 (permalink)  
Old 12-15-2005
PradeepRed PradeepRed is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 25
tried what you suggested but it did not work. It gave me the following error message.

grep: illegal option -- F
Usage: grep -hblcnsviw pattern file . . .

Pls suggest if i might be doing something wrong.

Regards
  #4 (permalink)  
Old 12-16-2005
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2005
Location: London
Posts: 222
try

egrep -f targets /big/data/file

where targets is the file that contains all patterns line by line
Closed Thread

Bookmarks

Tags
regex, regular expressions

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 02:46 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