The UNIX and Linux Forums  

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
GREP and Retrieve Line by Line maxmave Shell Programming and Scripting 2 06-03-2008 08:45 AM
Grep a number from a line in ksh rodluo Shell Programming and Scripting 3 12-09-2007 06:31 AM
grep the line only if next line matches pbsrinivas Shell Programming and Scripting 11 07-10-2007 05:51 AM
Grep using line command PradeepRed Shell Programming and Scripting 3 12-16-2005 10:37 AM
grep only one line asoosai UNIX for Dummies Questions & Answers 3 05-30-2003 11:04 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-18-2008
Registered User
 

Join Date: May 2008
Posts: 9
How to grep only 1st line

how to grep the line no of the first pattern match in a file having multiple line of pattern match.

linke i want to know the line no for the word "the" the first time it appears in the file, now a file is going to have the word "the" many times.. how to grep the first line no

for me -m 1'the' or -m 1"the" is not working!!!

kindly suggest somthing..
Reply With Quote
Forum Sponsor
  #2  
Old 05-18-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
sed -n '/the/=' file
or simply

Code:
grep -n "the" file | head -n 1
Reply With Quote
  #3  
Old 05-18-2008
Registered User
 

Join Date: May 2008
Posts: 9
thnx man!!!
Reply With Quote
  #4  
Old 05-19-2008
agn agn is offline
Registered User
 

Join Date: Feb 2008
Posts: 97
Code:
awk '/the/ { print NR; exit }' file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0