![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Line number of an occurrence using grep
Hi All,
is there a way to extract the line number of an occurrence using grep? I know that with the -n option it prints out the line number as well. I would like to assign the line number to a variable. Thanks, Sarah |
|
|||
|
thank you all, how do I access the first value of the variable in case of more than one occurrence? I tried var[0]...but with no success ---------- Post updated at 05:37 AM ---------- Previous update was at 04:14 AM ---------- Actually I am interested only in the first. Code:
grep -n 'pattern ' inputfile | read number_var junk echo $number_var doesn't work. Other methods work but I don't know how to access the first value in the returned variable. I solved with Code:
ISTHERE=`grep -n total tmp.tmp3 | head -1 | cut -d : -f 1` I'm smart too!
Last edited by f_o_555; 11-24-2009 at 09:14 AM.. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using grep to extract line number | mskarica | Shell Programming and Scripting | 8 | 06-26-2008 03:47 AM |
| Grep a number from a line in ksh | rodluo | Shell Programming and Scripting | 3 | 12-09-2007 09:31 AM |
| grep the string with the line number | salaathi | Shell Programming and Scripting | 4 | 12-04-2007 11:42 AM |
| Get Filename and Line Number using grep | ceemh3 | UNIX for Dummies Questions & Answers | 4 | 09-17-2007 11:35 AM |
| is there any why to get the number of line in grep result ? | umen | UNIX for Dummies Questions & Answers | 1 | 03-16-2006 09:56 AM |