grep on specific line of the file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

grep on specific line of the file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-28-2008
rider29 rider29 is offline
Registered User
 
Join Date: May 2008
Last Activity: 13 April 2012, 7:48 PM EDT
Posts: 41
Thanks: 2
Thanked 0 Times in 0 Posts
grep on specific line of the file

Hi,

how can we search for a word (with case ignore )on specific line numbers

ex:

Awk /^regEX/ with condition on first line or second line

Awk/^ regex1/ on line 1

Awk /^regEX2/ on line 3


thanks in advance

Last edited by rider29; 05-28-2008 at 03:43 PM..
Sponsored Links
    #2  
Old 05-28-2008
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 19 September 2014, 2:11 PM EDT
Location: The Netherlands
Posts: 7,716
Thanks: 123
Thanked 537 Times in 507 Posts
For the second line:


Code:
/^regEX/ && NR==2

Regards
Sponsored Links
    #3  
Old 05-28-2008
rider29 rider29 is offline
Registered User
 
Join Date: May 2008
Last Activity: 13 April 2012, 7:48 PM EDT
Posts: 41
Thanks: 2
Thanked 0 Times in 0 Posts
thank you, here how can we search with ignore case using awk' /^test/' ?
    #4  
Old 05-28-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 22 September 2014, 3:20 PM EDT
Location: Out running a Marathon.
Posts: 2,329
Thanks: 72
Thanked 153 Times in 142 Posts
Hammer & Screwdriver another approach, albeit a bit different

To find out about a particular line, say the 4th line of xx lines:


Code:
cat myfile | head -4 | tail -1 | grep -i "test"

OK, not very elegant, but a way to return info about a specific line of text in a file.
Sponsored Links
    #5  
Old 05-29-2008
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 19 September 2014, 2:11 PM EDT
Location: The Netherlands
Posts: 7,716
Thanks: 123
Thanked 537 Times in 507 Posts
Quote:
Originally Posted by rider29 View Post
thank you, here how can we search with ignore case using awk' /^test/' ?

Code:
 awk 'toupper($0) ~ /^TEST/{do your suff here..}' 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
fetch last line no form file which is match with specific pattern by grep command Himanshu_soni Shell Programming and Scripting 13 02-01-2011 06:37 AM
Grep specific records from a file of records that are separated by an empty line Atrisa UNIX for Dummies Questions & Answers 4 12-14-2010 05:51 AM
grep a specific line from a file Max89 Shell Programming and Scripting 4 11-24-2009 12:31 PM
grep specific line ryandegreat25 Shell Programming and Scripting 6 07-21-2009 04:46 AM
grep a word from a specific line blurboy Shell Programming and Scripting 3 01-23-2008 03:13 AM



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