get 3rd column of nth line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get 3rd column of nth line
# 1  
Old 12-20-2010
Power get 3rd column of nth line

hi;
i have a file.txt and its 9th, 10th and 11th line lines are:
Code:
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. Smilie

Last edited by gc_sw; 12-20-2010 at 09:45 AM..
# 2  
Old 12-20-2010
Something like this?
Code:
awk 'NR>8{print $3} /===/{exit}' file

# 3  
Old 12-20-2010
unfortunately;

Code:
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)
# 4  
Old 12-20-2010
Quote:
Originally Posted by gc_sw
unfortunately;

Code:
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 /\===/.
# 5  
Old 12-20-2010
tried no error has returned but also there is no result Smilie empty..
# 6  
Old 12-20-2010
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?
# 7  
Old 12-20-2010
The above (untested) command prints 1 extra line, try this:
Code:
awk '/===/{exit} NR>8{print $3}' file

This is what I get:
Code:
$ 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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace Value of nth Column of Each Line Using Array

Hello All, I am writing a shell script with following requirement: 1. I have one input file as below CHE01,A,MSC,INO CHE02,B,NST,INC CHE03,C,STM,INP 2. In shell script I have predefined array as below: Array1={A, B, C} Array2= {U09, C04, A054} (6 Replies)
Discussion started by: angshuman
6 Replies

2. Shell Programming and Scripting

Taking nth column and putting its value in n+1 column using awk

Hello Members, Need your expert opinion how to tackle below. I have an input file that looks like below: USS|AWCC|AFGAW|93|70 USSAA|Roshan TDCA|AFGTD|93|72,79 ALB|Vodafone|ALBVF|355|69 ALGEE|Wataniya (Nedjma)|DZAWT|213|50,550 I like output file in below format: ... (7 Replies)
Discussion started by: umarsatti
7 Replies

3. Shell Programming and Scripting

awk to search for specific line and replace nth column

I need to be able to search for a string in the first column and if that string exists than replace the nth column with "-9.99". AW12000012012 2.38 1.51 3.01 1.66 0.90 0.91 1.22 0.82 0.57 1.67 2.31 3.63 0.00 AW12000012013 1.52 0.90 1.20 1.34 1.21 0.67 ... (14 Replies)
Discussion started by: ncwxpanther
14 Replies

4. Shell Programming and Scripting

AWK script to create max value of 3rd column, grouping by first column

Hi, I need an awk script (or whatever shell-construct) that would take data like below and get the max value of 3 column, when grouping by the 1st column. clientname,day-of-month,max-users ----------------------------------- client1,20120610,5 client2,20120610,2 client3,20120610,7... (3 Replies)
Discussion started by: ckmehta
3 Replies

5. Shell Programming and Scripting

Calculating average for every Nth line in the Nth column

Is there an awk script that can easily perform the following operation? I have a data file that is in the format of 1944-12,5.6 1945-01,9.8 1945-02,6.7 1945-03,9.3 1945-04,5.9 1945-05,0.7 1945-06,0.0 1945-07,0.0 1945-08,0.0 1945-09,0.0 1945-10,0.2 1945-11,10.5 1945-12,22.3... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

6. Shell Programming and Scripting

Using AWK to find top Nth values in Nth column

I have an awk script to find the maximum value of the 2nd column of a 2 column datafile, but I need to find the top 5 maximum values of the 2nd column. Here is the script that works for the maximum value. awk 'BEGIN { subjectmax=$1 ; max=0} $2 >= max {subjectmax=$1 ; max=$2} END {print... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

7. Shell Programming and Scripting

1st column,2nd column on first line 3rd,4th on second line ect...

I need to take one column of data and put it into the following format: 1st line,2nd line 3rd line,4th line 5th line,6th line ... Thanks! (6 Replies)
Discussion started by: batcho
6 Replies

8. Shell Programming and Scripting

grep data on 2nd line and 3rd column

How do I grep/check the on-hand value on the second line of show_prod script below? In this case it's a "3". So if it's > 0, then run_this, otherwise, quit. > ./show_prod Product Status Onhand Price shoe OK 3 1.1 (6 Replies)
Discussion started by: joker_789us
6 Replies

9. Shell Programming and Scripting

Awk multiple lines with 3rd column onto a single line?

I have a H U G E file with over 1million entries in it. Looks something like this: USER0001|DEVICE001|VAR1 USER0001|DEVICE001|VAR2 USER0001|DEVICE001|VAR3 USER0001|DEVICE001|VAR4 USER0001|DEVICE001|VAR5 USER0001|DEVICE001|VAR6 USER0001|DEVICE002|VAR1 USER0001|DEVICE002|VAR2... (4 Replies)
Discussion started by: SoMoney
4 Replies

10. Shell Programming and Scripting

How to extract 3rd line 4th column of a file

Hi, Shell script: I would need help on How to extract 3rd line 4th column of a file with single liner Thanks in advance. (4 Replies)
Discussion started by: krishnamurthig
4 Replies
Login or Register to Ask a Question