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
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 05:29 AM
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 07:19 AM
Appending the line number and a seperator to each line of a file ? pjcwhite Shell Programming and Scripting 4 03-20-2007 10:29 PM
Unix Script with line number at beginning of each line. mascorro Shell Programming and Scripting 5 06-19-2006 01:34 PM
identifying duplicates line & reporting their line number stresslog UNIX for Dummies Questions & Answers 5 04-23-2006 09:43 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 09-23-2005
Registered User
 

Join Date: Sep 2005
Posts: 5
how to know the line number

hi all, how to know the line that the file currently reading

example:
exec 4<$1
while read eachline <&4
do
if [ "$eachline" == "POST" ]
then
/*here i want to which line number when it reads 'POST'

fi
done

please comment , thanks
Reply With Quote
Forum Sponsor
  #2  
Old 09-23-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Try this grep solution

Code:
grep -n 'POST' input.file
or this

awk solution

Code:
awk '{ ++i; if ( $0 ~ /POST/ ) print i,$0 }' input.file
vino

Last edited by vino; 09-23-2005 at 02:35 AM.
Reply With Quote
  #3  
Old 09-23-2005
Registered User
 

Join Date: Jul 2005
Location: England
Posts: 183
Or if you need it within the construct of your shell script, $line will contain the current line number that has just been read

Code:
line=0
exec 4<$1
while read eachline <&4
do
line=$((line + 1)
if [ "$eachline" == "POST" ]
then
/*here i want to which line number when it reads 'POST'

fi
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:40 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