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

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 05-28-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 28 March 2015, 9:32 AM EDT
Location: The Netherlands
Posts: 7,730
Thanks: 128
Thanked 544 Times in 512 Posts
For the second line:


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

Regards
Sponsored Links
    #3  
Old Unix and Linux 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 Unix and Linux 05-28-2008
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 23 March 2015, 1:20 PM EDT
Location: Within two miles of a Dunkin donuts.
Posts: 2,351
Thanks: 80
Thanked 159 Times in 146 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. Unix or Linux Image
Sponsored Links
    #5  
Old Unix and Linux 05-29-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 28 March 2015, 9:32 AM EDT
Location: The Netherlands
Posts: 7,730
Thanks: 128
Thanked 544 Times in 512 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 09:05 PM.