get 3rd column of nth line

hi;
i have a file.txt and its 9th, 10th and 11th line lines are:

RbsLocalCell=S2C1                                       maxPortIP  4            (this is 9th line)
RbsLocalCell=S3C1                                       maxPortIP  4            (this is 10th line)
RbsLocalCell=S1C1                                       maxPortIP  4            (this is 11th line)
=============================================================================   (this is 12th line)
Total: 3 results                                                                (this is 13th line)

how can i get the 4 there? i have to say;
"get the 3rd column of 9th, 10th and 11th lines."

another problem is that; this text is produced in every 10min. and sometimes it becomes 3-lined (9,10,11), sometimes 2-lined (9,10) where sometimes 6-lined (9,10,11,12,13,14). so i have to put it in a loop saying;
"get the 3rd column of 9th, 10th, 11th, ..., 14th lines if it exists."

hope it is clear. thx. :slight_smile:

Something like this?

awk 'NR>8{print $3} /===/{exit}' file

unfortunately;

nawk: syntax error at source line 1
context is
NR>8{print >>> $3} /= <<<
nawk: bailing out at source line 1

(since my machine is solaris, i am using nawk )

Try with /\===/ .

tried no error has returned but also there is no result :frowning: empty..

Is there by any chance a line containing === before line number 8?

---------- Post updated at 03:35 PM ---------- Previous update was at 03:32 PM ----------

Could you post a bigger sample of your data file?

The above (untested) command prints 1 extra line, try this:

awk '/===/{exit} NR>8{print $3}' file

This is what I get:

$ cat file
1
2
3
4
5
6
7
8
RbsLocalCell=S2C1                                       maxPortIP  4
RbsLocalCell=S3C1                                       maxPortIP  4
RbsLocalCell=S1C1                                       maxPortIP  4
=============================================================================
Total: 3 results                                                             
$
$ awk '/===/{exit} NR>8{print $3}' file
4
4
4

ok this is my whole data:

Log start: 101220-171509 - 192.168.1.1 - gc_sw.log

PORTAREA> list maxPorts

101220-17:15:19 10.14.3.49 7.1j  stopfile=/tmp/21632
=================================================================================================================
PORT                                                      Attribute         Value
=================================================================================================================
RbsLocalCell=S2C1                                       maxPortIP  4
RbsLocalCell=S3C1                                       maxPortIP  4
RbsLocalCell=S1C1                                       maxPortIP  4
=================================================================================================================
Total: 3 results

there is a === before 8th line but neither nawk '/\===/{exit} NR>8{print $3}' file nor nawk 'NR>8{print $3} /\===/{exit}' file gave result :frowning:

awk 'NR>8 && /===/{exit} NR>8{print $3}' file
1 Like

ok now :slight_smile:
nawk 'NR>8 && /\===/{exit} NR>8{print $3}' file has given result. thx Franklin :slight_smile:

Can't we just:

awk '/RbsLocalCell/{print $3}' file
1 Like

If that's the whole content of the file, sure...:smiley:

1 Like