How to grep only 1st line | 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 !!

How to grep only 1st line

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-19-2008
St.Fartatric St.Fartatric is offline
Registered User
 
Join Date: May 2008
Last Activity: 30 May 2008, 3:09 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
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..
Sponsored Links
    #2  
Old 05-19-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 10 Times in 8 Posts

Code:
sed -n '/the/=' file

or simply


Code:
grep -n "the" file | head -n 1

Sponsored Links
    #3  
Old 05-19-2008
St.Fartatric St.Fartatric is offline
Registered User
 
Join Date: May 2008
Last Activity: 30 May 2008, 3:09 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
thnx man!!!
    #4  
Old 05-19-2008
agn agn is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 6 August 2013, 7:49 AM EDT
Posts: 345
Thanks: 0
Thanked 21 Times in 21 Posts

Code:
awk '/the/ { print NR; exit }' file

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
How to grep the line with error where keyword in next line is known. manishdivs Shell Programming and Scripting 4 09-16-2011 10:21 AM
Sed or Grep to delete line containing patter plus extra line rocketman88 Shell Programming and Scripting 2 06-30-2010 06:59 AM
cat file1 read line-per-line then grep -A 15 lines down in fileb irongeekio Shell Programming and Scripting 6 01-28-2009 05:30 AM
Grep or other ways to output line above and/or below searched line sammac UNIX for Dummies Questions & Answers 2 07-24-2008 02:28 AM
grep the line only if next line matches pbsrinivas Shell Programming and Scripting 11 07-10-2007 08:51 AM



All times are GMT -4. The time now is 09:41 AM.