![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 | 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Try this grep solution
Code:
grep -n 'POST' input.file awk solution Code:
awk '{ ++i; if ( $0 ~ /POST/ ) print i,$0 }' input.file
Last edited by vino; 09-23-2005 at 02:35 AM. |
|
#3
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |